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
