I have two tests that extend AbstractTestNGSpringContextTests. Both of them use the same context, and autowire the same variable.
For reasons unknown to myself, TestOne.setup() works without any problems. TestTwo.setup() always fails. The most remarkable thing is that TestOne and TestTwo consistently exhibited the same behavior.Code:@ContextConfiguration(locations = { "classpath:/modules.xml" } ) public class TestOne extends AbstractTestNGSpringContextTests { @Autowired(required=true) private IService service; @BeforeClass(alwaysRun=true) public void setup() { // pass Assert.assertNotNull(service); } .... } @ContextConfiguration(locations = { "classpath:/modules.xml" } ) public class TestTwo extends AbstractTestNGSpringContextTests { @Autowired(required=true) private IService service; @BeforeClass(alwaysRun=true) public void setup() { // fail Assert.assertNotNull(service); } .... }
I inserted breakpoints at each setup functions and DependencyInjectionTestExecutionListener.prepareTe stInstance(TestContext). The order of execution is reverse for the two tests.
How could this be possible?


Reply With Quote