3

When testing with spring and @ContextConfiguration Is there an option to exclude some of the base class contexts? for example

@ContextConfiguration(locations = {"context1.xml", "context2.xml"})
public class Base{

and extending class

public class someClass extends Base{

now I want someClass to use context1.xml but NOT context2.xml. is there a way to exclude it? the issue is: I have a base class for all my tests (300 tests). I want all of them to use context1 which is a mock context that overrides the original one. Only one class should use the original context in order to test it (if the Base will not have it in its locations{} it will use the original).

1 Answer 1

3

As already mentioned, excluding contexts will not be possible.

However, I would advise you to take a look at the new Spring 3 bean profiles.

By specifying / activating the correct profiles you should be able to achieve the same thing in a cleaner way...

A nice article on unit / integration testing with spring bean profiles can be found here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.