首页 文章

跳过TestNG测试执行期间抛出的具体异常

提问于
浏览
2

This is related to the question How to create own annotation for junit that will skip test if concrete exception was thrown during execution?, but for TestNG.

我寻求一种解决方案来配置TestNG集成测试,以便在已知的基础结构异常列表中跳过(而不是失败),这些异常可能会偶尔出现 .

浏览TestNG代码后,我了解到使用 IHookable 或其他侦听器无法实现这一点 . TestNG也没有't have anything similar to JUnit'对象 . 此外,使用所有基础结构例外来扩展TestNG的 SkipException 对我来说不是一个选择 .

我错过了什么?

1 回答

  • 1

    实现IInvokedMethodListener并在afterInvocation方法中执行类似的操作

    public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
    
    if(testResult.getThrowable().getClass().equals(YourExceptionClass.class))
         testResult.setStatus(TestResult.SKIP);
    }
    

    在testng.xml中设置此侦听器,或者基于您正在执行测试 .

相关问题