1.引入相关依赖
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency>
2.新建java单元测试文件加上spring配置文件的注解
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath*:spring/*.xml"}) public class MapperTest { @Autowired private ProductTypeMapper mapper; @Test public void testProductType(){ ProductTypeExample example = new ProductTypeExample(); List<ProductType> list = mapper.selectByExample(example); System.out.println(list); } }