从测试套件执行时,是否有办法强制Maven Surefire或JUnit指示失败的测试类的名称? [英] Is there a way to force Maven Surefire or JUnit to indicate the name of the failing test class when executed from a Test Suite?
问题描述
我的问题:当已经从测试套件中执行了此类的时候,是否有一种方法可以强制Maven Surefire(或JUnit?)指示失败的测试类的名称?
My question: Is there a way to force Maven Surefire (or JUnit?) to indicate the name of the failing test class when this class has been executed from a Test Suite?
现在,长的故事.
想象一下,您有一个JUnit测试套件可以启动两个JUnit测试.
Imagine you have a JUnit test suite that launches two JUnit tests.
测试类示例:
public class TestOne {
@Test
public void foo() {
assertTrue(false);
}
@Test
public void bar() {
assertTrue(false);
}
}
@UnitTest
public class TestTwo {
@Test
public void foo() {
assertFalse(true);
}
}
和测试套件:
@RunWith(Suite.class)
@SuiteClasses(value = { TestOne.class, TestTwo.class })
public class MySuite {
}
现在,如果我运行测试套件(mvn test -Dtest=MySuite
),将出现以下错误:
Now, if I run the test suite (mvn test -Dtest=MySuite
), I will have the following errors:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running caf.opm.preclosing.junit.MySuite
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!
Results :
Failed tests:
foo(my.project.junit.TestOne)
bar(my.project.junit.TestOne)
foo(my.project.junit.TestTwo)
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0
因此,阅读这些行后,我可以轻松地检测出哪些类和测试失败了.
So reading these lines, I can easily detect which classes and tests are failing.
但是,在target/surefire-reports/
目录中,我只有一个文件MySuite.txt
,其中三个测试均失败.
这种情况的后果之一是,我的哈德逊大楼将为我显示以下信息:
However, in target/surefire-reports/
directory, I have only one file, MySuite.txt
where the three tests are failing.
One of the consequences of such situation is that my Hudson build will show me the following information:
All Failed Tests
Test Name Duration Age
>>> my.project.junit.MySuite.foo 0.0 1
>>> my.project.junit.MySuite.bar 0.0 1
>>> my.project.junit.MySuite.foo 0.0 1
如您所见,
识别失败的测试变得更加困难,例如,由于TestOne.foo()
和TestTwo.foo()
失败,我在JUnit报告中看到了两个MySuite.foo
错误.
当然,我可以通过读取失败测试的日志来检索测试类的名称,但这并不是真正的解决方案...
As you can see, it becomes harder to identify the failing tests, and for example, as TestOne.foo()
and TestTwo.foo()
failed, I saw two MySuite.foo
errors in my JUnit report.
Of course I can retrieve the name of the test class by reading the logs of the failed test, but it's not really a solution...
所以我的问题是知道是否可以强制Surefire(或JUnit?)指示测试类的名称.
So my question is to know if I can force Surefire (or JUnit?) to indicate the name of test class.
谢谢.
推荐答案
每个测试类只能得到一个文件,所以花了一点时间才弄清楚这个:您正在使用测试套件.
I get a single file per test class, so it took me a moment to figure this one out: You're using a test suite.
使用测试套件时,所有测试结果都将以套件名称结尾在单个文件中.
When using test suites, all the test results end up in a single file with the name of the suite.
没有选项可以更改此行为.尝试提交功能请求.
There is no option to change this behavior. Try to file a feature request.
这篇关于从测试套件执行时,是否有办法强制Maven Surefire或JUnit指示失败的测试类的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!