依赖架包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
在单元测试文件下,测试类上添加注解@SpringBootTest
@RunWith(SpringRunner.class)
@SpringBootTest //扫描SpringbootTestApplication启动类,启动类扫描mapper
public class SpringbootTestApplicationTests {
@Autowired
UserTestMapper userTestMapper;
@Test
public void testuserTestMapper() {
UserTestCriteria example =new UserTestCriteria();
com.testfan.model.UserTestCriteria.Criteria cri = example.createCriteria();
cri.andLoginnameLike("z");
Criteria cri2= example.createCriteria();
cri2.andLoginpassBetween("1", "1000");
example.or(cri2);
userTestMapper.selectByExample(example);
}
}
注意:SpringbootTestApplicationTests 和SpringbootTestApplication需要在同一级目录下,否则扫描不到启动类文件
如何开启sql查询日志
在application.properites文件中添加配置
#对应的包com.testfan.dao 根据实际情况而定
logging.level.com.testfan.dao=debug