我有以下场景:
@Transactional
@SpringBootTest
@ActiveProfiles("test")
@AutoConfigureMockMvc
@AutoConfigureWireMock(port = 0)
public abstract class IntegrationTest {
}
public class Test1 extends IntegrationTest {
// Tests that use WireMock
}
@ActiveProfiles("specific-case-test") // This causes another Application Context to be created.
public class Test2 extends IntegrationTest {
// Tests that use WireMock
}
public class Test3 extends IntegrationTest {
// Tests that use WireMock
}
Run Code Online (Sandbox Code Playgroud)
测试在所有这些场景中成功运行:
在所有这些情况下,最后运行的测试都会失败:
我已经调查过这个问题,它与 Spring Application Context 和 WireMock 有关。
到底是怎么回事?让我们考虑测试按以下顺序运行:Test1, Test2, Test3 …