本文共 1515 字,大约阅读时间需要 5 分钟。
话不多说,直入正题。
添加依赖org.springframework.boot spring-boot-starter-test test junit junit org.springframework spring-test 5.2.2.RELEASE compile 如果上面四个依赖不能完成Junit测试 就使用下面两个依赖(下面是可以的 已经测试过)============================================================= org.springframework.boot spring-boot-test org.springframework.boot spring-boot-starter-test 2.4.1 junit junit
测试类中进行测试
@SpringBootTest(classes = {CmfzdemoApplication.class}) //必写 大括号中的值为启动类的名称@RunWith(SpringJUnit4ClassRunner.class) //必写public class AppTest { @Autowired private ArticleService articleService; @Autowired private AlbumService albumService; @Test public void Test1(){ System.out.println(articleService.getArticle()); } @Test public void Test2(){ System.out.println(albumService.getAlbum()); }}
1.添加所需依赖 2.测试类上添加 SpringBootTest RunWith 注解 3.SpringBootTest 注解中大括号的值填写启动类的名称,RunWith 注解照抄 4.方法名上添加Test注解
上述四部完成后,即可进行方便快捷的springjunit测试。
转载地址:http://hzoai.baihongyu.com/