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

Posted backpacker

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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   技术图片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的主要内容,如果未能解决你的问题,请参考以下文章

How to fix Error: listen EADDRINUSE while using nodejs

how to add them, how to multiply them

in a devstack Openstack env, how to start a service, such as aodh-listener

[转]How to add new table in NopCommerce

How to add the ApplicationPoolIdentity to a SQL Server Login

How to add elements to a List in Scala