Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // подделывать бэкенд можно и нужно!
- // Только это называется "эмулировать" или "мокать".
- @Test // Если вы тестируете страницу со списком файлов, то так и надо писать:
- public void userCanSeeAllUploadedFiles() {
- stubFor(get(urlEqualTo("/user/files/"))
- .withHeader("Accept", equalTo("text/xml"))
- .willReturn(aResponse()
- .withStatus(200)
- .withHeader("Content-Type", "text/xml")
- .withBody("<response><file>file1.jpg</file><file>file2.jpg</file></response>")));
- open("http://localhost:8080/files");
- $$("#my-files").shouldHave(texts("file1.jpg", "file2.jpg"));
- }
- @Test // А если тестируете страницу загрузки файлов, тогда это отдельный тест, и в нём другая проверка:
- public void userCanSeeUploadFile() {
- open("http://localhost:8080/upload");
- $("#upload-file").uploadFile("src/test/resources/new-picture.jpg");
- $("#submit").click();
- verify(postRequestedFor(urlMatching("/user/files"))
- .withRequestBody(matching(".*<file>new-picture.jpg</file>.*"))
- .withHeader("Content-Type", notMatching("application/json")));
- }
Advertisement
Add Comment
Please, Sign In to add comment