@RunWith和@ContextConfiguration的作用解析

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = {"classpath:applicationContext.xml"} )

@RunWith(SpringJUnit4ClassRunner.class):
@Runwith的作用是让测试的实例在spring容器的环境下运行,那么什么是spring容器的环境,这个容器环境就是如:service, controller等包的使用就是spring容器。
@ContextConfiguration:
1、 他的作用是引入配置文件applicationContext.xml,如果没有写配置文件名的话则会根据测试的名字去匹配

    @ContextConfiguration
    public void test{
    }

2、可以写多个配置文件
用,隔开如下:

@ContextConfiguration( locations = {"classpath:applicationContext.xml","classpath:applicationContext2.xml"} 

你可能感兴趣的:(java,ssm)