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


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.

链接地址: http://www.djcxy.com/p/82046.html

上一篇: 配置使用@Mock和@InjectMocks

下一篇: @ContextConfiguration排除基类上下文