首页 > 其他 > 详细

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

时间:2019-05-28 13:06:56      阅读:126      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/backpacker/p/10936455.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!