Dirty Context does not get refreshed

Anonymous avatarAnonymous created an issue

Hi - I noticed a serious issue when using Springockito:

If partially load a Spring context in a component tests and mock out some beans using Springcokito, the context won't get reloaded in the next integration test if I mark the context as dirty.

This is what I have on the component test:

@DirtiesContext(classMode = AFTER_CLASS)
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:spring-classify-test.xml")
public class....

    private SomeServiceInterface someServiceInterface;

As you can see, the context is loaded from *spring-classify-test.xml.

The next test in the suite is an Integration test and it has the following annotations:

@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = { "classpath:/spring-service-integration-test.xml" })
public ...

    private SomeServiceInterface someServiceInterface;

The problem is: the SomeServiceInterface will be a mock. The context did not get reloaded for some reason.

I digged into the Spring code and could not find the root cause of the problem.

May you please advise?

Cheers mate.

Comments (8)

  1. pbatko

    I briefly looked into your problem but could't it. What I observed is that context is reloaded even if @ContextConfiguration settings in two cases match but have different layout of @WrapWithSpy or @ReplaceWithMock (because of fake location generation).

    Could you recheck your tests?

  2. Claudinei Junior

    Hi - thanks for your input - very much appreciated.

    You are right wrt the context being reloaded when their @ContextConfiguration's match - but the problem I'm raising here is a little bit subtler than that.

    The context configuration for IntegrationTest and ComponentTest are different - they load the contexts from different files. The thing is: I want (and need) to mock out objects from the Component Test's Context - but not from the Integration Test.

    The problem is: if I mock out objs from the Component Test, the Integration Test's Context (a different one, loaded from a different file) also gets changed. That should not happen at all as I'm asking Springockito to change solely the context of the component tests.

    I'm not sure I got your point when it comes to @WrapWithSpy and @ReplaceWithMock and fake location generation. May you please give me a little bit more of information so that a little bit of understanding can penetrate my tortoiseshell cranium?

    I don't rule out the possibility that I'm misusing Springockito - and that the problem lies on how I structured my tests and not on Springockito.

    I raised this issue in the StackOverflow seeking for help - please refer to this link case you need further information: http://stackoverflow.com/questions/14636897/mocked-objects-in-context-during-tests-execution

    Cheers mate.

  3. pbatko

    Fake location is more a implementation detail than the feature. They're talked in this jira16.

    I have difficulties with reproducing the problem. Could you provide simple proof of concept project with with the problem occuring?

  4. pbatko

    In recent commit springockito-integration module was created. I tried to reproduce the issue but failed to get erroneous result. Here you can check if it corresponds to your problem.

    Hope it'll help you.

  5. Claudinei Junior

    Hi - thanks again for your input - very much appreciated.

    yes, I'll upload a simple project demonstrating the issue I'm facing - probably at some point within the next 10 hours.

    Re. springockito-integration - quite a lot of code was commited. I'll have a go with it and will let you know the outcome.


  6. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.