asolntsev

wiremock-in-tests

Nov 10th, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. // подделывать бэкенд можно и нужно!
  2. // Только это называется "эмулировать" или "мокать".
  3.  
  4. @Test // Если вы тестируете страницу со списком файлов, то так и надо писать:
  5. public void userCanSeeAllUploadedFiles() {
  6.     stubFor(get(urlEqualTo("/user/files/"))
  7.             .withHeader("Accept", equalTo("text/xml"))
  8.             .willReturn(aResponse()
  9.                 .withStatus(200)
  10.                 .withHeader("Content-Type", "text/xml")
  11.                 .withBody("<response><file>file1.jpg</file><file>file2.jpg</file></response>")));
  12.    open("http://localhost:8080/files");
  13.    $$("#my-files").shouldHave(texts("file1.jpg", "file2.jpg"));
  14. }
  15.  
  16. @Test // А если тестируете страницу загрузки файлов, тогда это отдельный тест, и в нём другая проверка:
  17. public void userCanSeeUploadFile() {
  18.   open("http://localhost:8080/upload");
  19.   $("#upload-file").uploadFile("src/test/resources/new-picture.jpg");
  20.   $("#submit").click();
  21.  
  22.   verify(postRequestedFor(urlMatching("/user/files"))
  23.             .withRequestBody(matching(".*<file>new-picture.jpg</file>.*"))
  24.             .withHeader("Content-Type", notMatching("application/json")));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment