ITeye博客

Spring框架和Junit的结合使用

西子湖畔的家 · 2016-03-02 20:37 · Java基础 · Spring框架 · 开源软件 · junit · Spring · 测试 · Markdown

在spring框架做测试时,需要将所使用到的bean全部加载进容器中才可以进行测试,采用spring框架和junit结合的方法进行测试,配置如下:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:application.test.xml")

其中:@RunWith是指定使用的单元测试执行类

   @ContextConfiguration是需要加载的配置文件,其中locations是一个字符串数组:

  String[] locations() default {};

 因此支持一次加载多个配置文件。(这里是

classpath*:application.test.xml

)加载进来,即可加载其所包含的配置,并且可以像使用普通junit一样进行测试。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。