博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot进行Junit测试
阅读量:4179 次
发布时间:2019-05-26

本文共 1515 字,大约阅读时间需要 5 分钟。

话不多说,直入正题。

添加依赖

org.springframework.boot
spring-boot-starter-test
test
junit
junit
org.springframework
spring-test
5.2.2.RELEASE
compile
org.springframework.boot
spring-boot-test
如果上面四个依赖不能完成Junit测试 就使用下面两个依赖(下面是可以的 已经测试过)=============================================================
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/

你可能感兴趣的文章
Linux下rz,sz与ssh,SecureCRT的配合使用
查看>>
一个使用Pro*C实现增删改查的小例子
查看>>
Save could not be completed. Eclipse国际化的问题解决
查看>>
Xblo(JSP+Servlet+JavaBean+Oracle单用户Blog)
查看>>
Unable to use IEC module under PortablePython_1.1_py2.5.4
查看>>
实用英文地址书写格式
查看>>
在oracle中通过connect by prior来实现递归查询!
查看>>
百度空间如何才能另存为 mht
查看>>
How to Reset or Change Microsoft Office 2007 Product License Key or Volume License Key (VLK)
查看>>
使用java concurrent调用xmlp api生成pdf
查看>>
Oracle日期计算之INTERVAL
查看>>
Oracle PL/SQL之EXCEPTION
查看>>
Oracle PL/SQL之EXCEPTION -- WHEN OTHERS THEN
查看>>
Oracle PL/SQL之VARCHAR2 QUALIFIER
查看>>
Oracle PL/SQL之处理index不连续的table类型变量
查看>>
Oracle PL/SQL之嵌套表(Nested Table)
查看>>
Oracle PL/SQL之令人不解的提示(nls_date_format)
查看>>
Oracle PL/SQL之GROUP BY ROLLUP
查看>>
Oracle PL/SQL之GROUP BY CUBE
查看>>
蓝桥杯2018省赛 - A3 乘积尾零
查看>>