有没有办法强制 Maven Surefire 或 JUnit 在从测试套件执行时指示失败的测试类的名称?
我的问题:当从测试套件执行此类时,有没有办法强制 Maven Surefire(或 JUnit?)指示失败的测试类的名称?
现在,这是一个很长的故事。
假设您有一个 JUnit 测试套件,它启动两个 JUnit 测试。
测试类示例:
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
),我将出现以下错误:
-------------------------------------------------------
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
因此,阅读这些行,我可以轻松检测到哪些课程和测试不及格。
但是,在 target/surefire-reports/
目录中,我只有一个文件 MySuite.txt
,其中三个测试均失败。 这种情况的后果之一是我的 Hudson 构建将向我显示以下信息:
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
错误。 当然,我可以通过读取失败测试的日志来检索测试类的名称,但这并不是真正的解决方案...
所以我的问题是知道我是否可以强制 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?
Now, the long story.
Imagine you have a JUnit test suite that launches two JUnit tests.
Examples of test classes:
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);
}
}
and the test suite:
@RunWith(Suite.class)
@SuiteClasses(value = { TestOne.class, TestTwo.class })
public class 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.
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
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...
So my question is to know if I can force Surefire (or JUnit?) to indicate the name of test class.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我每个测试类都有一个文件,所以我花了一些时间才弄清楚这一点:您正在使用测试套件。
使用测试套件时,所有测试结果最终都保存在一个带有套件名称的文件中。
没有选项可以更改此行为。尝试提交功能请求。
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.