我正在尝试检测 @AfterMethod 中跳过的测试以进行报告。
我可以捕获失败或通过的测试,但当跳过测试时它似乎不会输入。
我的测试:
@Test
public void method1 () {
Assert.fail("created failure");
}
@Test (dependsOnMethods = {"method1"})
public void method2 () {}
我的方法:
@AfterMethod
protected void afterMethod(ITestResult result){
switch (result.getStatus()) {
case ITestResult.FAILURE:
...
break;
case ITestResult.SKIP:
...
break;
case ITestResult.SUCCESS:
...
break;
}
例如,这里我只检索失败,但跳过不会在 after 方法中传递
知道如何做吗?
谢谢!
最佳答案
我通过实现 ITestListener 类找到了一种方法,您可以在那里找到一个示例:
基本上,您所做的就是创建一个类,该类将捕获所有 ITestResult,甚至是跳过的结果,并在其中重新定义您想要执行的操作:
public class IntegrationTestListener implements ITestListener {
public void onTestSkipped(ITestResult result) {
// do your stuff here
}
}
并在测试中使用它,这样做:
@Listeners ({IntegrationTestListener.class})
public class NotAScenario extends BasicScenario {
@Test
public void test1() {
}
}
关于java - 使用 testng 检测 @afterMethod 中跳过的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37029997/