使用TestContextManager准备实例时出现java BeanCreationException
我想了解以下两种变体之间的区别:
1:
@RunWith(Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath*:/spring/spring-test-core-service.xml", inheritLocations = false)
class MyMapperTest {
private TestContextManager testContextManager;
public MyMapperTest() throws Exception{
testContextManager = new TestContextManager(getClass());
testContextManager.prepareTestInstance(this);
}
}
2:
@RunWith(Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath*:/spring/spring-test-core-service.xml", inheritLocations = false)
class MyMapperTest {
private TestContextManager testContextManager;
public MyMapperTest() {
testContextManager = new TestContextManager(getClass());
try {
testContextManager.prepareTestInstance(this);
} catch(Exception e) {
Assert.fail(e.getMessage());
}
}
}
在我的测试用例中,我使用了构造函数的第二个变体。当我单独进行测试时,一切正常。但当它与CI构建中的其他测试类一起运行时,它失败了
因此,在一次故障排除之后,我将构造函数更改为上面的变体1,删除了try。。拦网。成功了
但这种行为背后的原因是什么
共 (0) 个答案