1

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?

Sowmiya
  • 313
  • 2
  • 12
  • 1
    Can you describe the details behind *"this failed"*? – Gergely Bacso Apr 28 '16 at 12:34
  • 1
    You probably get an exception in both case. On the first case, you ignore it hence the test pass. On the second case, you call Assert.fail when catching the exception hence the test fail. – Jean-François Savard Apr 28 '16 at 12:40
  • Yes Jean. My bad! Looks like spring-test-core-service.xml is not located and hence the beans are not available in the test context. – Sowmiya Apr 29 '16 at 09:22

0 Answers0