Spring Boot 跟Junit进行集成测试

   

    <!--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);
    }
    
}

 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页