BeanCreationException while preparing instance using TestContextManager

96 Views Asked by At

I would like to understand the difference between the below two variants:

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());
       }
    }
}

In my testcase, I was using the second variation of the constructor. When I ran my test separately, it worked all fine. But when it ran with other Test classes in the CI build, this failed.

Hence, after a troubleshooting, I changed the constructor to look like the variant 1 above, removing the try..catch block. It worked.

But what is the reason behind this behavior?

0

There are 0 best solutions below