JUnit Suite 内的日志信息
我目前正在尝试在日志文件中写入 JUnite Suite 失败测试的总数。
我的测试套件定义如下:
@RunWith(Suite.class)
@SuiteClasses({Class1.class, Class2.class etc.})
public class SimpleTestSuite {}
我尝试定义一个规则,该规则会在测试失败时增加错误总数,但显然我的规则从未被调用。
@Rule
public MethodRule logWatchRule = new TestWatchman() {
public void failed(Throwable e, FrameworkMethod method) {
errors += 1;
}
public void succeeded(FrameworkMethod method) {
}
};
关于我应该做什么来实现这种行为有什么想法吗?
I'm currently trying to write inside a log file the total number of failed tests from a JUnite Suite.
My testsuite is defined as follows:
@RunWith(Suite.class)
@SuiteClasses({Class1.class, Class2.class etc.})
public class SimpleTestSuite {}
I tried to define a rule which would increase the total number of errors when a test fails, but apparently my rule is never called.
@Rule
public MethodRule logWatchRule = new TestWatchman() {
public void failed(Throwable e, FrameworkMethod method) {
errors += 1;
}
public void succeeded(FrameworkMethod method) {
}
};
Any ideas on what I should to do to achieve this behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码对我有用。我怀疑您没有将错误声明为静态。
考虑一下 JUnit 在执行每个测试方法之前会创建一个固定装置的新实例。
The following code works for me. I suspect you are not declaring
errors
as static.Consider that JUnit creates a new instance of the fixture before exercising each test method.