Hi,
My suite of tests contains a series of unit tests (that load an object from the application context and then inject it with necessary mocks) and and integration tests (that load a series of objects from the same application context without any mocking in place).
My test classes are typically configured with the following annotation
and beans may be loaded using the @Autowired annotationCode:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:spring/*Context.xml"})
The problem that I am seeing is that all tests run fine when run individually, but when together as part of a suite I am seeing strange behaviour in the integration test.
My understanding was that the application context would be loaded on the running of each test class....however, this does not seem to be the case.
Unit test A loads a bean B from the application context and then injects this with a mock object C.
However, when my integration test runs it loads a bean D, which in turn loads bean B but does not perform an explicit mocking.
I would have presumed that when I ran my integration test that the mock object would no longer be in memory.
How can I ensure that the application context is reloaded for each test, or at least just for the integration test??


Reply With Quote