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);
}

Junit : how to add listener, and how to extends RunListener to override behaviors while failed的更多相关文章

  1. 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: ...

  2. android ListView 可缩放,支持左右上下手势

    public class ZoomListView extends ListView implements SwipeListener { public static enum Action { Le ...

  3. java 实现自定义事件

    import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; i ...

  4. Netty学习笔记(二)——netty组件及其用法

    1.Netty是 一个异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端. 原生NIO存在的问题 1) NIO的类库和API繁杂,使用麻烦:需要熟练掌握Selector.Se ...

  5. How to use Junit Listener

    JUnit Listeners If you want to do some operations when your tests are started, passed, finished, fai ...

  6. 获取JUnit的执行结果

    junit执行之后会有一个结果展示,下面就来看一下怎么获取这些结果并将其存储为一个对象 junit代码如下: package test; import org.junit.After; import ...

  7. junit源码解析--测试驱动运行阶段

    前面的博客里面我们已经整理了junit的初始化阶段,接下来就是junit的测试驱动运行阶段,也就是运行所有的testXXX方法.OK,现在我们开始吧. 前面初始化junit之后,开始执行doRun方法 ...

  8. junit源码解析--核心类

    JUnit 的概念及用途 JUnit 是由 Erich Gamma 和 Kent Beck 编写的一个开源的单元测试框架.它属于白盒测试,只要将待测类继承 TestCase 类,就可以利用 JUnit ...

  9. JUnit源码分析 - 扩展 - 自定义RunListener

    RunListener简述 JUnit4中的RunListener类用来监听测试执行的各个阶段,由RunNotifier通知测试去运行.RunListener与RunNotifier之间的协作应用的是 ...

随机推荐

  1. TP-Link 路由器 如何在现有的环境中改善无线信号传输质量

    http://service.tp-link.com.cn/detail_article_346.html

  2. liboqs-量子安全密码算法开源C库

    liboqs是一个用于量子安全密码算法的开源C库. 一,概述 liboqs提供: 量子安全 密钥封装机制(KEM)和数字签名算法的开源实现的集合: 这些算法的通用API: 测试工具和基准测试例程. l ...

  3. dubbo-admin监控搭建2.6.0版本

    首先介绍一下dubbo的一个比较大的改变,那就是在2.6.1及2.6.1以后的版本当中,dubbo将一分为二,分为Dubbo-RPC和Dubbo-Admin,而在2.6.1以前的版本中Dubbo-Ad ...

  4. ASP.NET Core WebAPI帮助页--Swagger简单使用1.0

    1.什么是Swagger? Swagger是一个规范且完整的框架,提供描述.生产.消费和可视化RESTful API,它是为了解决Web API生成有用文档和帮助页的问题.   2.为啥选用swagg ...

  5. 01-jar包操作---idea打jar包

    文章:idea打包java可执行jar包 maven项目的话,使用maven命令,直接build就可以打jar包.

  6. 求二叉搜索树的第k小的节点

    题目描述: /** * 给定一棵二叉搜索树,请找出其中的第k小的结点. * 例如, (5,3,7,2,4,6,8)中, * 按结点数值大小顺序第三小结点的值为4. * 这是层序遍历: * 5 * 3 ...

  7. p1364 医院设置 题解

    思路:floyd 很普通的思路. 先用floyd求出两个边之间的距离,然后乘以人数. 代码: #include<iostream> #include<cstring> usin ...

  8. AttributeError: module 'Crypto.PublicKey.RSA' has no attribute 'import_key'

    I solved this problem by pip install pycryptodome

  9. Ubuntu 安装matlab2013b

    下载软件包: 链接:http://pan.baidu.com/s/1bHoFHc 密码:lugc 还要注意软件的解压的问题: 链接:http://pan.baidu.com/s/1geBEQyf 密码 ...

  10. LAMP 搭建,wordpress.xcache,powerdns及poweradmin

    一,概念 CGI: CGI全称是通用网关接口(Common Gateway Interface),是外部应用程序与与服务器之间的接口标准,是在CGI程序和web服务器之间传递信息的规程 CGI是一段程 ...