Я заново редактирую вопрос, так как он может быть полезен для других.
Я пытаюсь привыкнуть к тестированию клиентов с помощью макетных http-конечных точек с помощью Wiremock.
Очень простой сценарий теста включает
- тестовый случай, который вызывает конечную точку с заглушкой (работает хорошо)
- тестовый сценарий, который вызывает непустую конечную точку (не удается)
Случай с конечной точкой без заглушки сам по себе успешен, но кажется, что использованный WireMockRule проверяет список несопоставленных вызовов и выдает ошибку, когда список не пуст.
Тест выполняется без ошибок в более ранних версиях Wiremock (1.43), на самом деле я пробую его с версией 2.21.
Тестовый класс выглядит так:
public class HttpFetcherTest {
@Rule
public WireMockRule wireMockRule = new WireMockRule(18089);
@Before
public void init() {
// only one endpoint is mocked
stubFor(get(urlEqualTo("/aBody.txt")).willReturn(
aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody("aBody")));
}
/**
* Test calls a defined endpoint. Runs smoothly.
* @throws Exception
*/
@Test
public void found() throws Exception {
//call the mocked endpoint
String result = Request.Get("http://localhost:18089/aBody.txt").execute().returnContent().asString();
// we expect the mocked return value from the stub
assertTrue("aBody".equals(result));
}
/**
* The test calls an endpoint that is undefined. Expected behaviour is: a HttpResponseException
* is thrown. This is successful but the test fails anyway as the list of unmatched matches in WireMockRule is inspected
* and the unmatched call is found and interpreted as an error.
* This means: test fails although it is successful.
*
* This was not an issue in earlier versions of Wiremock - it runs perfectly in 1.43.
* @throws Exception
*/
@Test(expected = HttpResponseException.class)
public void notFound() throws Exception {
// call an endpoint that is not mocked - we expect a HttpResponseException
String result = Request.Get("http://localhost:18089/NOT_FOUND").execute().returnContent().asString();
}
}
Я озадачен ....
Спасибо, Ишиидо