Java 在套件中运行测试时,如何打印测试日志(通过/失败)?
我有一个包含两个测试的套件。我想打印每个测试,如果它通过或失败时,测试完成运行。 我不想为每个测试添加代码,因为我有很多测试,我需要在套件中完成。 这是我拥有的一个套房的例子:Java 在套件中运行测试时,如何打印测试日志(通过/失败)?,java,junit,automation,junit4,suite,Java,Junit,Automation,Junit4,Suite,我有一个包含两个测试的套件。我想打印每个测试,如果它通过或失败时,测试完成运行。 我不想为每个测试添加代码,因为我有很多测试,我需要在套件中完成。 这是我拥有的一个套房的例子: @RunWith(ConcurrentSuite.class) @Concurrent(threads = 6) @Suite.SuiteClasses({ test1.class, test2.class, test3.class,
@RunWith(ConcurrentSuite.class)
@Concurrent(threads = 6)
@Suite.SuiteClasses({
test1.class,
test2.class,
test3.class,
test4.class,
})
public class ExampleSuite {
}
tnx 如果您的测试类都继承自一个抽象的基本测试类,那么您可以向这个测试类添加一个Testwatcher,然后实现您想要测试失败或测试成功的任何反应:
abstract class BaseTest {
@Rule
public TestWatcher watchman = new TestWatcher() {
// define logger here
@Override
protected void failed(Throwable e, Description description) {
logger.error(description, e);
}
@Override
protected void succeeded(Description description) {
logger.info(description);
}
};