The spring framework documentation states:
In the unlikely case that a test may
‘dirty’ the application context,
requiring reloading – for example, by
changing a bean definition or the
state of an application object –
Spring’s testing support provides
mechanisms to cause the test fixture
to reload the configurations and
rebuild the application context before
executing the next test.
Can someone elaborate this? I am just not getting it. Examples would be nice.
Each JUnit test method is assumed to be isolated, that is does not have any side effects that could cause another test method to behave differently. This can be achieved by modifying the state of beans that are managed by spring.
For example, say you have a bean managed by spring of class
MySpringBeanwhich has a string property with a value of"string". The following test methodtestBeanStringwill have a different result depending if it is called before or after the methodtestModify.use the
@DirtiesContextannotation to indicate that the test method may change the state of spring managed beans.