How to test/validate many spring context?

I have created a java component which it will be use by other people. And I would like to perform unit-testing to verify many spring configurations.

What I've done today : One class test by configuration file

  • config 01 : Config01Test.java
  • config 02 : Config02Test.java
  • config 03 : Config03Test.java

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"/spring/config01.xml" })
    @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
    public class Config01Test{
    }
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"/spring/config02.xml" })
    @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
    public class Config02Test{
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"/spring/config03.xml" })
    @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
    public class Config03Test{}
    

But I was wondered if it we could done it in one java class. As for example load a different spring context for each test : (with a Junit Annotation ... like @LoadSpringContext( blablabla )

@RunWith(SpringJUnit4ClassRunner.class)  
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) 
public class ConfigTest{

    @LoadSpringContext(locations = {"/spring/config01.xml")
    public testConfig01(){
      // implement test
    }

    @LoadSpringContext(locations = {"/spring/config02.xml")
    public testConfig02(){
      // implement test
    }

    @LoadSpringContext(locations = {"/spring/config03.xml")
    public testConfig03(){
      // implement test
    }
}

Thanks,

Answers


You can remove the Spring annotations: @RunWith, @DirtiesContext, @LoadSpringContext and load the spring context by hand in every test case.

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/application-context.xml");

Need Your Help

Keeping window of another application active while still receiving mouse events from another app's window?

objective-c cocoa nswindow appkit nsevent

Is there a way to have my app's window receive keyboard and/or mouse events (i.e. user clicking on window's buttons) while still retaining focus to another, unrelated app?