当前位置:网站首页>Junit测试中常用的断言
Junit测试中常用的断言
2022-06-12 14:18:00 【小小微的博客】
1、断言捕获的异常信息中是否含有某字符串内容
try {
//TODO
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String msg = sw.toString();
String exp = "客户信息不存在,不能修改";
Assert.assertNotEquals(-1, msg.indexOf(exp));
}
2、断言捕获的异常是否是某个指定异常
try {
//TODO
} catch (Exception e) {
Assert.assertEquals(e.getClass(), RPCTimeoutException.class);
}
3、断言消耗的时间是否是指定时间,其中System.currentTimeMillis()是获取当前系统时间,start是开始时间
String taketime = Long.toString(System.currentTimeMillis() - start);
Assert.assertNotSame(-1, taketime.indexOf("10"));
这里将消耗的时间(Long类型)转换成string类型后,将其与预计的时间进行对比
边栏推荐
- [wp][入门]攻防世界-game
- C secret arts script Chapter 5 (paragraph) (Section 3)
- Postgresql14 installation and use tutorial
- QT multi thread drawing and real-time refreshing method
- 你敢信?開發一個管理系統我只用了兩天
- Leetcode 2185. Counts the string containing the given prefix
- Mémoire de l'examen d'entrée à l'université
- Module yaml error: Unexpected key in data: static_context [line 9 col 3]
- NetCore结合CAP事件总线实现分布式事务——入门(1)
- Configuring OSPF pseudo connection for Huawei devices
猜你喜欢

Autofac初学(1)

Location (I) error: command erred out with exit status

Redis data deletion policy in 2022

QT realize picture dragging
![[Writeup]BUU SQL COURSE1[入门级]](/img/eb/1b2541b04ca231cb07f1f3706f51c7.png)
[Writeup]BUU SQL COURSE1[入门级]

Player actual combat 22 to solve the problems of flower screen and Caton

PMP敏捷知识点

Interview (XI) futu written test questions

Appnium (II) installation and basic use of mitmproxy

Is Shell Scripting really a big technology?
随机推荐
Webdriver opens in full screen and a prompt "Chrome is under the control of automatic test software" appears in Chrome
The original Xiaoyuan personal blog project that has been around for a month is open source (the blog has basic functions, including background management)
Codeforces Round #798 (Div. 2)(A~D)
Machine learning learning notes
Ppt cannot be opened, always prompt how to fix it
win10_ Home Edition cannot use remote desktop, and can be accessed by remote desktop.
Appnium (I) basic use of appnium
NetCore结合CAP事件总线实现分布式事务——入门(1)
华为设备配置OSPF伪连接
Nesting of C language annotations
新技术:高效的自监督视觉预训练,局部遮挡再也不用担心!
Player actual combat 22 to solve the problems of flower screen and Caton
Lua callinfo structure, stkid structure resolution
Analysis of lua source code
Player practice 15 xdemux and avcodecparameters
C secret script Chapter 3 (detailed explanation of string function) (Section 2)
Leetcode 2185. Counts the string containing the given prefix
Reverse order of Excel
Design of PLC intelligent slave station based on PROFIBUS DP protocol
TestEngine with ID ‘junit-vintage‘ failed to discover tests