Announcement Announcement Module
Collapse
No announcement yet.
ContextConfiguration inheritance mixing XML and bean configuration in Spring tests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ContextConfiguration inheritance mixing XML and bean configuration in Spring tests

    Hi,

    I have a base class for several integrations tests that is defined like this:

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:/META-INF/my-xml-context.xml")
    public class BaseClassForTesting {
    ..
    }
    Other tests inherits from this configuration like this:
    Code:
    public class MyITest1 extends BaseClassForTesting {
    ..
    }
    or

    Code:
    @ContextConfiguration("classpath:/META-INF/my-other-xml-context.xml")
    public class MyITest2 extends BaseClassForTesting {
    ..
    }
    In the case of "MyITest2" the context configurations are merged automatically. My problem arrise when I have a test class defined like this:

    Code:
    @ContextConfiguration(classes = MyConf.class)
    public class MyITest3 extends BaseClassForTesting {
    ..
    }
    I.e. I'm using a Spring bean configuration instead of an XML configuration for "MyITest3". This results in the following stack trace:

    Code:
    ...
    Caused by: java.lang.IllegalStateException: Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to load an ApplicationContext from [MergedContextConfiguration@5297bebd testClass = MyITest3, locations = '{classpath:/META-INF/my-xml-context.xml}', classes = '{class com.xyz.MyConf}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader'].
    	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:258)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
    	... 29 more
    Am I doing something wrong or is this not supported? Are there any work-arounds?

    Regards,
    /Johan

  • #2
    Hello Johan, is this still a problem and/or have you found a workaround?

    /Martin

    Comment

    Working...
    X