<!--junit单元测试的依赖-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--springboot做单元测试的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
在测试类上使用注解。@SpringBootTest
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class TestDao {
//飘红不影响使用
@Autowired
private StudentDao studentDao;
@Test
public void testSelectAll(){
List<Student> students = studentDao.selectAll();
students.forEach(System.out::println);
}
}