Results 1 to 2 of 2

Thread: Application context not refreshed between unit tests

  1. #1

    Default Application context not refreshed between unit tests

    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
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"classpath:spring/*Context.xml"})
    and beans may be loaded using the @Autowired annotation

    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??

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I suggest a read of the test chapter in the reference guide, as that is explained in there. Simply use the @DirtiesContext annotation....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •