Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring test - @ContextConfiguration exclude base class context

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).

like image 535
user1116377 Avatar asked Nov 28 '25 05:11

user1116377


1 Answers

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.

like image 80
ddewaele Avatar answered Nov 30 '25 20:11

ddewaele