1

我想了解以下两种变体之间的区别:

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..catch 块。有效。

但这种行为背后的原因是什么?

4

0 回答 0