How to valid many spring context
I have created a java component wich it will be use by other people. And I would like to make unit test to check many spring configurations.
What I've done today : One class test by configuration file
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 diffent 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,
您可以删除Spring注释: @RunWith
, @DirtiesContext
, @LoadSpringContext
并在每个测试用例中手动加载spring上下文。
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/application-context.xml");
链接地址: http://www.djcxy.com/p/82050.html
上一篇: 通过直接使用上下文获取的Spring / Mock组件
下一篇: 如何有效地许多春天背景