Description
Andreas Höhmann opened SPR-14834 and commented
I have spring based integration tests, all these tests are based on a base test class which extends org.springframework.test.context.testng.AbstractTestNGSpringContextTests.
If I run all these IT's ... then "sometimes" (I guess if at least one of the test fails) the following test (not all, strange behavior) are also not successful because the whole spring-context startup crash and that because of a missing bean of type "ConfigurableEnvironment" ... yes I have somewhere in the configuration classes code like this:
@Autowired
ConfigurableEnvironment environment;
And in the real world the application have no problem with that :)
But in the test environment there is something strange ... I have no idea :-/
Here is the "important" stuff of that class maybe you see immediately that something is wrong :)
/**
* Base class for integration tests which require a complete Spring context.
*
* <p>
* Takes care of following aspects:
* <ul>
* <li>mark as {@link DirtiesContext}</li>
* <li>load environment properties from <code>META-INF/spring-test/hscm-environment.properties</code> (are generated during build or must be
* provided manually in class path)</li>
* </ul>
* </p>
*
* <p>
* Loading of environment-properties:
* <ol>
* <li>add <b>generated</b> test properties "classpath:META-INF/spring-test/hscm-environment.properties" to simulate "jndi environment", see
* {@link TestContextLoader}</li>
* <li>add (optional) customized environment-properties for tests, see {@link TestContextLoader}, see {@link TestEnvironmentProperties}</li>
* </ol>
* </p>
*
* <p>
* Currently the whole customizing for HSCM IT's are located inside the test-resources:
* <ul>
* <li>default: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/hscm-test</li>
* <li>default: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/pcmplus-test</li>
* <li>for some tests: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/hscm-test-freeze</li>
* <li>for some tests: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/pcmplus-test-freeze</li>
* </ul>
* </p>
*
* <p>
* You can override every property with the help of the {@link TestEnvironmentProperties} annotation.
* </p>
*
* @author Sebastian Paul
* @author Andreas Höhmann
*/
@WebAppConfiguration
@ContextConfiguration( //
locations = { //
"classpath:META-INF/spring-test/test-applicationContext.xml", //
"classpath:META-INF/spring-test/test-spring-propertyplaceholder.xml", //
}, loader = AbstractHscmSpringIntegrationTest.TestContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@SuppressWarnings("javadoc")
public abstract class AbstractHscmSpringIntegrationTest extends AbstractTestNGSpringContextTests {
....
// autowired some spring basics
@Autowired
protected transient MockHttpServletRequest request;
@Autowired
protected transient MockHttpServletResponse response;
@Autowired
protected transient WebApplicationContext webApplicationContext;
// but also autowire some core bean which should be available for all tests
@Autowired
protected transient HscmConfigurationManager configurationManager;
@Autowired
protected transient HscmInitializationManager hscmInitializationManager;
...
@Override
@AfterMethod(alwaysRun = true)
protected final synchronized void springTestContextAfterTestMethod(final Method testMethod) throws Exception {
// FIXME concurrency issues in the TestContext framework - #10532
LOGGER.debug("Shutdown spring context ...");
super.springTestContextAfterTestMethod(testMethod);
LOGGER.debug("Shutdown spring context done");
}
@Override
@BeforeMethod(alwaysRun = true)
protected final synchronized void springTestContextBeforeTestMethod(final Method testMethod) throws Exception {
// FIXME concurrency issues in the TestContext framework - #10532
LOGGER.debug("Start spring context ...");
super.springTestContextBeforeTestMethod(testMethod);
LOGGER.debug("Start spring context done");
}
...
}
Affects: 3.2.17
Issue Links:
- AbstractTransactionalTestNGSpringContextTests not working as expected when an EJB with TransactionAttribute.REQUIRES_NEW is encountered [SPR-6132] #10800 AbstractTransactionalTestNGSpringContextTests not working as expected when an EJB with TransactionAttribute.REQUIRES_NEW is encountered
- ApplicationContext fails to load in TestNG test if previous test is annotated with @DirtiesContext [SPR-12918] #17517 ApplicationContext fails to load in TestNG test if previous test is annotated with
@DirtiesContext
- Do not synchronize
ApplicationContext
creation in the TestContext framework [SPR-10536] #15166 Do not serialize ApplicationContext creation in the TestContext framework