SSM搭建Spring单元测试环境
1、建立一个单元测试类MapperTest

2、推荐Spring的项目可以使用Spring的单元测试,可以自动注入我们需要的组件。
导入SpringTest依赖包。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.7.RELEASE</version>
<scope>test</scope>
</dependency>

3、在MapperTest加入注解@ContextConfiguration,指定spring配置文件的位置。
@ContextConfiguration(locations={"classpath:applicationContext.xml"})

4、增加注解@RunWith(SpringJUnit4ClassRunner.class)

5、现在可以直接使用@Autowired注入要使用的组件

6、测试是否可以得到我们注入的Mapper

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:79
阅读量:125
阅读量:33
阅读量:116
阅读量:90