SpringBoot集成Junit
1.添加junit的起步依赖
<!--springboot继承junit的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
2.编写测试类
@RunWith(SpringRunner.class)//代表用谁去执行
@SpringBootTest(classes = SpringbootMybatisApplication.class)
public class MybatisTest {
@Autowired
private UserMapper userMapper;//测谁就注入谁
@Test
public void test(){
List<User> users = userMapper.queryUserList();
System.out.println(users);
}
}
注: 此文章只为记录开发过程中的错误,学习,如发现侵权请私信删除