You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
running the following test: @ContextConfiguration(locations = {"....spring.xml"})
public class TestngTest extends AbstractTransactionalTestNGSpringContextTests{
@Test
@DirtiesContext
public void testMethod1() {
}
@Test
@DirtiesContext
public void testMethod2(){
}
}
the springcontext will be closed in the first test as a result due to @DirtiesContext, but no new context will be loaded before running the second test, hence code depending on the existence of a valid context will fail.
Is this intended?
does context reloading onoly work accross different test classes, ie. not inside one and the same test class?
According to the spring documentation (http://static.springframework.org/spring/docs/2.1.x/reference/testing.html#testcontext-framework):
"you may annotate your test method with @DirtiesContext (assuming DirtiesContextTestExecutionListener has been configured, which is the default) to cause the test fixture to reload the configurations and rebuild the application context before executing the next test case." - it seems like my test should have worked.. - or?
kai:)
Affects: 2.5 RC1
The text was updated successfully, but these errors were encountered:
the springcontext will be closed in the first test as a result due to @DirtiesContext,
but no new context will be loaded before running the second test, hence code depending
on the existence of a valid context will fail.
That is partially correct:
After careful analysis, it turns out that the ApplicationContext is in fact closed and
recreated as expected; however, due to how the test instance is instrumented with the
TestContextManager in AbstractTestNGSpringContextTests, dependency injection is not being
performed on the test instance between individual test methods with TestNG.
Thus, although a new ApplicationContext is being created, it is not being supplied
to your test instance via ApplicationContextAware semantics. In other words,
this.applicationContext references the old, closed, dirtied context, which is
presumably not what you desire.
does context reloading onoly work accross different test classes, ie. not inside one
and the same test class?
Well, it works with JUnit 3.8 and JUnit 4.4, because JUnit instantiates a new instance
of your test class between test method execution; however, as you indirectly noticed,
it does not work as you might have expected with the abstract TestNG base test classes.
I'll have a look into a possible work-around or solution for you and get back to you.
The Spring TestContext Framework's dependency injection support and handling of @DirtiesContext have been refactored so that all dependencies (including an
ApplicationContext set via ApplicationContextAware semantics) will be "reinjected"
into the test instance after any test method which declares @DirtiesContext.
Please give one of the upcoming nightly builds a try to see if this meets your needs.
kai lilleby opened SPR-3880 and commented
running the following test:
@ContextConfiguration
(locations = {"....spring.xml"})public class TestngTest extends AbstractTransactionalTestNGSpringContextTests{
}
the springcontext will be closed in the first test as a result due to
@DirtiesContext
, but no new context will be loaded before running the second test, hence code depending on the existence of a valid context will fail.Is this intended?
does context reloading onoly work accross different test classes, ie. not inside one and the same test class?
According to the spring documentation (http://static.springframework.org/spring/docs/2.1.x/reference/testing.html#testcontext-framework):
"you may annotate your test method with
@DirtiesContext
(assuming DirtiesContextTestExecutionListener has been configured, which is the default) to cause the test fixture to reload the configurations and rebuild the application context before executing the next test case." - it seems like my test should have worked.. - or?kai:)
Affects: 2.5 RC1
The text was updated successfully, but these errors were encountered: