【问题标题】:TestNG Custom Reporter include test description instead of nameTestNG 自定义报告器包含测试描述而不是名称
【发布时间】:2017-11-07 14:50:19
【问题描述】:

我想为 TestNG xml 测试结果实现自定义报告器。 我目前使用 JUnitReportReporter。 我的结果 xml 目前看起来像这样:

testcase name="testSearchForProductAndVerifyFirstFoundItem" time="55.516" classname="com.jpard.jaf.test.SearchForAnItemTests"

我只是想用测试描述替换测试用例名称 如@Test(description = "测试结果中的第一个项目是搜索的项目")。 我怎样才能以最简单的方式做到这一点。 非常感谢!

【问题讨论】:

    标签: xml testng test-reporting test-results


    【解决方案1】:

    我做了简单的扩展 JUnitReportReporter 类并覆盖 getTestName 方法以显示在 xml 报告中方法名称和描述。该类如下所示:

    public class CustomReporter extends JUnitReportReporter {
    
    @Override
    protected String getTestName(ITestResult tr) {
        return tr.getMethod()
                 .getMethodName() + ": " + tr.getMethod()
                                             .getDescription();
    }
    

    }

    我希望它可以帮助任何寻找此问题的人。

    【讨论】:

      【解决方案2】:

      我认为您必须实现 IMethodInterceptor 接口,该接口将返回方法实例列表 IMethodInstance 然后 从该列表中一一获取所有实例,然后

      desc = instance.getMethod().getDescription();
      

      方法getDescription()

      看看here

      【讨论】:

        猜你喜欢
        • 2013-02-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-16
        • 1970-01-01
        相关资源
        最近更新 更多