在spring框架做测试时,需要将所使用到的bean全部加载进容器中才可以进行测试,采用spring框架和junit结合的方法进行测试,配置如下:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath*:application.test.xml")
其中:@RunWith是指定使用的单元测试执行类
@ContextConfiguration是需要加载的配置文件,其中locations是一个字符串数组:
String[] locations() default {};
因此支持一次加载多个配置文件。(这里是
classpath*:application.test.xml
)加载进来,即可加载其所包含的配置,并且可以像使用普通junit一样进行测试。