Junit : how to add listener, and how to extends RunListener to override behaviors while failed
2024-09-05 13:26:30
http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html
org.junit.runner.notification
Class RunListener
java.lang.Object org.junit.runner.notification.RunListener
-
public class RunListener
- extends java.lang.Object
If you need to respond to the events during a test run, extend RunListener
and override the appropriate methods. If a listener throws an exception while processing a test event, it will be removed for the remainder of the test run.
For example, suppose you have a Cowbell
class that you want to make a noise whenever a test fails. You could write:
public class RingingListener extends RunListener {
public void testFailure(Failure failure) {
Cowbell.ring();
}
}
To invoke your listener, you need to run your tests through JUnitCore
.
public void main(String... args) {
JUnitCore core= new JUnitCore();
core.addListener(new RingingListener());
core.run(MyTestClass.class);
}
最新文章
- MySQL源码分析:源码文件结构及主要数据结构
- sql 内连接和外链接
- The median of multi ascending array
- 当一个页面出现多个checkbox全选时的处理
- ajax、post、get实例
- 我写了一个java实体类,implements了Serializable接口,然后我如何让serialversionUID自动生成
- docker note
- Hacker(七)----黑客常用术语和DOS命令
- Java程序执行Linux命令
- MSSQL、C# 、Winform、ASP.NET - 数据库备份与还原模块
- 【Java】ArrayList 的 toArray() 方法抛出 ClassCastException 异常
- SVN常用命令积累
- cursor 属性
- Winsock编程基础1
- linux内存 free命令 buffer cache作用
- macOS上实现Qt应用程序做文件关联打开
- python类之魔法方法
- Linux内核分析第二次作业
- 【转载】selenium与自动化测试成神之路
- deeplearningbook-chinese
热门文章
- LLVM4.0与3.5编译phase对比
- JS实现table表格在鼠标移动出现一行变色或者十字叉变色
- Jdk1.8的安装(Linux和windows)
- 02-springmvc分布式项目dataService项目配置
- Gym - 102040B Counting Inversion (数位dp)
- Windows 和 Linux 下生成以当前时间命名的文件
- 【leetcode】1259.Handshakes That Don't Cross
- chromedriver.exe,自动化web, 安装谷歌驱动,以及可能遇到的坑
- vue-cli中route和router的区别
- JavaWeb_Ajax通过JQuery和原生js异步传输数据