【问题标题】:WireMock affects other testsWireMock 影响其他测试
【发布时间】:2021-11-26 15:57:49
【问题描述】:

所有现有测试都带有注释

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles({"test"})

我已经添加了

spring-cloud-contract-wiremock

到我的项目并使用以下注释创建了一个测试:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock(port = 10000, stubs = {"classpath:stubs/mappings"})
@ActiveProfiles({"test"})

当我一起运行所有测试时,WireMock 测试之后的所有测试都开始失败。

问题如下:

Caught exception while invoking 'beforeTestMethod' callback on TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@42f3156d] for test method [public void com.example.MyClass.foo1()] and test instance [com.example.MyClassTest@5e3569e8]
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource...

这些失败的方法用以下注释:

@Test
@SqlGroup

【问题讨论】:

  • 出于好奇,您如何确定是 WireMock 导致了问题?
  • @Oozeerally 当我删除整个班级时,一切正常

标签: java spring spring-boot integration-testing wiremock


【解决方案1】:

我找到了解决方案。我有

ddl-auto: create-drop 

在我的配置中,但应该是

ddl-auto: create-only

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 2022-08-02
    相关资源
    最近更新 更多