• Junit : how to add listener, and how to extends RunListener to override behaviors while failed


    http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html

    org.junit.runner.notification
    Class RunListener

    java.lang.Object   extended by 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);
    }

  • 相关阅读:
    loadrunner监控linux之linux下安装rpc
    Linux中top命令参数详解
    使用jmeter监控服务器性能指标
    jmeter连接mysql数据库配置
    loadrunner--设置代理录制
    页面下载时间细分图组成
    linux网络配置
    科学把妹法
    简单而强大的bitset
    名言札记
  • 原文地址:https://www.cnblogs.com/backpacker/p/10936455.html
Copyright © 2020-2023  润新知