文章目录
Spring Boot集成单元测试调用dao,service
1 添加相关依赖
<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><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency>
2 新建测试类
importcom.geekmice.staging.staging.BaoProjectApiApplication;importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.test.context.SpringBootTest;importorg.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)@SpringBootTest(classes=Application.class)// Application 主启动类publicclassJzrTest{@AutowiredprivateUserDAO userdao;@Test//@Commit//@Transactionalpublicvoidtest(){System.out.println(userdao.select());}}
温馨提示:本人开发上线视频网站,有想要的看视频的,可以看看。小松鼠
本文转载自: https://blog.csdn.net/greek7777/article/details/132020334
版权归原作者 geekmice 所有, 如有侵权,请联系我们删除。
版权归原作者 geekmice 所有, 如有侵权,请联系我们删除。