I have two tests that extend AbstractTestNGSpringContextTests. Both of them use the same context, and autowire the same variable.

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

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?