WireMock测试单独运行,但在执行所有测试时却没有
我使用WireMock创建了一些集成测试。他们单独通过,但是当我执行test
gradle的任务时,他们会失败以下错误:
2022-05-09 11:42:40.077 ERROR 23116 --- [tp1400751713-44] WireMock : No response could be served as there are no stub mappings in this WireMock instance.
有关此的特殊性,它是一个弹簧应用程序,因此WireMock必须准备就绪,并在此之前准备就绪测试类是初始化的 这是我的测试课之一,另一个非常相似:
@ActiveProfiles({"test"})
@SpringBootTest(args = {"src/test/resources/data/productTestData.xml", "--operation=createProduct"})
@ExtendWith(OutputCaptureExtension.class)
public class CreateProductsFunctionalTest {
private static final String PRODUCT_CREATE_REQUEST_PATH = "product_create_request.json";
private static final String PRODUCT2_CREATE_REQUEST_PATH = "product2_create_request.json";
private static final String PRODUCT_CREATE_RESPONSE_PATH = "product_create_response.json";
private static final String PRODUCT2_CREATE_RESPONSE_PATH = "product2_create_response.json";
private static final int FLUENT_PORT = 8085;
@RegisterExtension
private static final WireMockExtension FLUENT_WM =
WireMockExtension.newInstance().options(wireMockConfig().port(FLUENT_PORT)).build();
@BeforeAll
static void setup() {
fluentMockAuthentication(FLUENT_WM, OAUTH_SUCCESS_RESPONSE_PATH, OK.value());
fluentMockGraphQL(FLUENT_WM, PRODUCT_CREATE_REQUEST_PATH, PRODUCT_CREATE_RESPONSE_PATH);
fluentMockGraphQL(FLUENT_WM, PRODUCT2_CREATE_REQUEST_PATH, PRODUCT2_CREATE_RESPONSE_PATH);
}
@DisplayName("when creating product information")
@Test
void shouldInvokeCreateProducts(final CapturedOutput output) {
assertThat(output).contains("Product with ref '00001111' successfully created");
assertThat(output).contains("Product with ref '00002222' successfully created");
}
}
固执发生在fluentMockAuthentication
和fluentmockgraphql
方法中。
I created some integration tests using wiremock. They pass individually, but when I execute the test
task from gradle they fail with the following error:
2022-05-09 11:42:40.077 ERROR 23116 --- [tp1400751713-44] WireMock : No response could be served as there are no stub mappings in this WireMock instance.
The special thing about this, it is a Spring ApplicationRunner, so the wiremock has to be ready and stubbed before the test class is initialized
Here is one of my test classes, the other is very similar:
@ActiveProfiles({"test"})
@SpringBootTest(args = {"src/test/resources/data/productTestData.xml", "--operation=createProduct"})
@ExtendWith(OutputCaptureExtension.class)
public class CreateProductsFunctionalTest {
private static final String PRODUCT_CREATE_REQUEST_PATH = "product_create_request.json";
private static final String PRODUCT2_CREATE_REQUEST_PATH = "product2_create_request.json";
private static final String PRODUCT_CREATE_RESPONSE_PATH = "product_create_response.json";
private static final String PRODUCT2_CREATE_RESPONSE_PATH = "product2_create_response.json";
private static final int FLUENT_PORT = 8085;
@RegisterExtension
private static final WireMockExtension FLUENT_WM =
WireMockExtension.newInstance().options(wireMockConfig().port(FLUENT_PORT)).build();
@BeforeAll
static void setup() {
fluentMockAuthentication(FLUENT_WM, OAUTH_SUCCESS_RESPONSE_PATH, OK.value());
fluentMockGraphQL(FLUENT_WM, PRODUCT_CREATE_REQUEST_PATH, PRODUCT_CREATE_RESPONSE_PATH);
fluentMockGraphQL(FLUENT_WM, PRODUCT2_CREATE_REQUEST_PATH, PRODUCT2_CREATE_RESPONSE_PATH);
}
@DisplayName("when creating product information")
@Test
void shouldInvokeCreateProducts(final CapturedOutput output) {
assertThat(output).contains("Product with ref '00001111' successfully created");
assertThat(output).contains("Product with ref '00002222' successfully created");
}
}
The stubbing happens in the fluentMockAuthentication
and fluentMockGraphQL
methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论