如何在运行中的一类或套房使用ANT的所有测试打印当前执行的JUnit测试方法是什么? [英] How to print current executing junit test method while running all tests in a class or suite using ANT?
问题描述
我有一组JUnit测试例,我使用的是从JUnit的ANT执行它们任务。在执行测试,在控制台中我能看到只有那些测试用例(Java类)正在运行,而不是测试方法。有没有一种方法,我可以打印当前执行的测试方法?或有任何其他方式比有自己的JUnit测试运行要做到这一点其他的?
样控制台输出
[JUnit的]运行examples.TestCase1
[JUnit的]测试运行:3,失败:0,错误:0,经过时间:2.835秒
相反,我希望得到像
输出 [JUnit的]运行examples.TestCase1
[JUnit的]运行examples.TestCase1.test1
[JUnit的]运行examples.TestCase1.test2
[JUnit的]运行examples.TestCase1.test3
[JUnit的]测试运行:3,失败:0,错误:0,经过时间:2.835秒
不幸的是,挂接到的JUnit没有什么好办法。对于与TDD制定了一个框架,这是惊人的敌意。
使用 @rule
而不是:
进口org.junit.rules.TestWatcher;
进口org.junit.runner.Description;
进口org.slf4j.Logger;
进口org.slf4j.LoggerFactory;/ **
*登录当前正在运行的测试。
*
*< P>典型用途:
*
*< P> {@ code @rule公共LogTestName logTestName =新LogTestName();}
*
*< P>另请参见:
*< BR> {@链接org.junit.Rule}
*< BR> {@链接org.junit.rules.TestWatcher}
* /
公共类LogTestName扩展TestWatcher { 私人最终静态记录器记录= LoggerFactory.getLogger(junit.logTestName); @覆盖
保护无效启动(说明描述){
log.debug(测试{},description.getMethodName());
}}
注:
我使用的是静态记录。这使得code执行得更快,但我的主要的原因是记录测试的名字是一个横切关注点:我想启用/禁用此记录在一个中心位置,而不是将其配置为每个测试类的。
另一个原因是,我有处理生成输出以及更容易配置一个固定的模式工具: - )
如果你不希望这样,那么就得到 description.getTestClass)记录器(
。
I have a set of JUnit Test Cases and I execute them from ANT using the junit task. While executing the tests, in the console I get to see only which test case(java class) is currently running, but not the test method. Is there a way I can print the current executing test method? Or is there any other way to do this other than having my own JUnit test runner?
Sample Console Output
[junit] Running examples.TestCase1
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.835 sec
Instead I wish to get the output like
[junit] Running examples.TestCase1
[junit] Running examples.TestCase1.test1
[junit] Running examples.TestCase1.test2
[junit] Running examples.TestCase1.test3
[junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.835 sec
Unfortunately, there is no good way to hook into JUnit. For a framework that was developed with TDD, it's astonishingly hostile.
Use a @Rule
instead:
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Log the currently running test.
*
* <p>Typical usage:
*
* <p>{@code @Rule public LogTestName logTestName = new LogTestName();}
*
* <p>See also:
* <br>{@link org.junit.Rule}
* <br>{@link org.junit.rules.TestWatcher}
*/
public class LogTestName extends TestWatcher {
private final static Logger log = LoggerFactory.getLogger( "junit.logTestName" );
@Override
protected void starting( Description description ) {
log.debug( "Test {}", description.getMethodName() );
}
}
Notes:
I'm using a static logger. That makes the code execute faster but my main reason is that logging test names is a cross-cutting concern: I would like to enable/disable this logging in a central place instead of configuring it for each test class.
Another reason is that I have tools which process the build output and those are easier to configure for a fixed pattern :-)
If you don't want this, then just get the logger for description.getTestClass()
.
这篇关于如何在运行中的一类或套房使用ANT的所有测试打印当前执行的JUnit测试方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!