Junit : how to add listener, and how to extends RunListener to override behaviors while failed
org.junit.runner.notification
Class RunListener
java.lang.Objectorg.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);
}
Junit : how to add listener, and how to extends RunListener to override behaviors while failed的更多相关文章
- win10系统在执行“ vagrant box add centos7 vagrant-centos-7.box”添加box时,报错“Vagrant failed to initialize at a very early stage: Failed to locate the powershell executable on the available PATH. ”
这个意思是:在有效的路径中未能执行PowerShell命令. 请检查PowerShell的安装和有效的路径,然后再尝试重新运行这个命令. 在环境变量path中添加powershell的路径,例如:C: ...
- android ListView 可缩放,支持左右上下手势
public class ZoomListView extends ListView implements SwipeListener { public static enum Action { Le ...
- java 实现自定义事件
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; i ...
- Netty学习笔记(二)——netty组件及其用法
1.Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端. 原生NIO存在的问题 1) NIO的类库和API繁杂,使用麻烦:需要熟练掌握Selector.Se ...
- How to use Junit Listener
JUnit Listeners If you want to do some operations when your tests are started, passed, finished, fai ...
- 获取JUnit的执行结果
junit执行之后会有一个结果展示,下面就来看一下怎么获取这些结果并将其存储为一个对象 junit代码如下: package test; import org.junit.After; import ...
- junit源码解析--测试驱动运行阶段
前面的博客里面我们已经整理了junit的初始化阶段,接下来就是junit的测试驱动运行阶段,也就是运行所有的testXXX方法.OK,现在我们开始吧. 前面初始化junit之后,开始执行doRun方法 ...
- junit源码解析--核心类
JUnit 的概念及用途 JUnit 是由 Erich Gamma 和 Kent Beck 编写的一个开源的单元测试框架.它属于白盒测试,只要将待测类继承 TestCase 类,就可以利用 JUnit ...
- JUnit源码分析 - 扩展 - 自定义RunListener
RunListener简述 JUnit4中的RunListener类用来监听测试执行的各个阶段,由RunNotifier通知测试去运行.RunListener与RunNotifier之间的协作应用的是 ...
随机推荐
- python异步IO编程(二)
python异步IO编程(二) 目录 开门见山 Async IO设计模式 事件循环 asyncio 中的其他顶层函数 开门见山 下面我们用两个简单的例子来让你对异步IO有所了解 import asyn ...
- 安装MySQL数据库并开启远程访问
一.安装MySQL数据库 MySQL安装在系统盘下(C:\Program Files),方便系统备份. 1.双击安装程序,勾选“I accept the license terms”,点击“Next” ...
- MySQL 5.7 免安装版 access denied 解决办法
MySQL 5.7 在Windows 下安装的过程很多人都写过了 但是安装完成后用 root 第一次登录时需要密码 可是我根本就没设密码嘛... 搞了半天最后终于搞定了 在执行 mysqld --in ...
- mysql统计表中条目个数的方法举例
说明:以下标红且加大括号的均需要替换为实际待查询的表名或数据库名. [1].统计某张或某几张表的数据量: select count(*) from {TABLE_NAME}; #or select c ...
- python学习-Python简介以及运行环境
Python语言是全世界几百种编程语言中的一个,诞生时间不算长,但是现在已经成为很热门的语言,近几年在TIOBE排行榜一直呈现上升趋势,截止19年2月,python已经超过C++成为排名第三的语言. ...
- 最完美ThinkPHP Nginx 配置文件
一个配置文件,完美支持普通,兼容,pathinfo,rewrite4种url模式,别怪我没提醒你收藏哦. 常见的静态文件404时也不会再去跑一遍fastcgi浪费资源. server { listen ...
- The Linux Kernel 4.15.0官方文档内核语言风格解读(留)
https://www.kernel.org/doc/html/v4.15/translations/zh_CN/coding-style.html 1.缩进 制表符是 8 个字符,所以缩进也是 8 ...
- RWD(Responsive Web Design)(转)
The key point is adapting to the user’s needs and device capabilities. Suppose a mobile user will be ...
- 使用rpm安装mysql5.6(简单安装 实验使用)
[root@localhost mysql]# cd /usr [root@localhost mysql]# mkdir mysql [root@localhost mysql]# cd mysql ...
- UVA - 12538 Version Controlled IDE (可持久化treap)
紫薯例题 #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3f3f3f; ],ch[ ...
org.junit.runner.notification.RunListener