【发布时间】: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