WireMock测试单独运行,但在执行所有测试时却没有

发布于 2025-01-27 10:16:57 字数 1901 浏览 5 评论 0原文

我使用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");
  }
}

固执发生在fluentMockAuthenticationfluentmockgraphql方法中。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文