我正在四处寻找,看看是否可以通过注释来完成我想要完成的任务。
基本上,我们有一堆 TestNG 测试用例,我们正在对其进行微观管理
示例:
@Test
public void reportingTest(){
Assert.true(false);
}
上面的方法会失败,但我们将所有内容包装在断言 try catch 中。
@Test
public void reportingTest(){
try {
Assert.true(false);
Report.batch(Enum.Pass, 106);
} catch (Throwable t) {
Report.batch(Enum.Fail, 106, "Test case has failed");
}
}
但是,经过数百个测试用例之后...... try catch 是非常麻烦的。
我正在努力完成这样的事情
@Reporting(id=106)
@Test
public void reportingTest(){
Assert.true(false);
}
在注释内部,我将能够捕获失败的断言并根据我的 ID 发送注销信息。
谢谢!
最佳答案
TestNG 提供 listeners您正在寻找的可能是 TestListener .
您可以从那里获得注释:tr.getMethod().getConstructorOrMethod().getMethod().getAnnotation(Reporting.class)
。
关于java - 自定义@Annotation以在运行时报告 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31334329/