【问题标题】:TestNG: how NOT to ignore @Test(testName) on method-levelTestNG:如何不忽略方法级别的@Test(testName)
【发布时间】:2012-11-07 15:59:57
【问题描述】:

我正在尝试将 @Test 中的 testName 属性用于我的 ReportNG html 输出。

不幸的是它说:

/**
* The name of the test  this test class should be placed in.  This
* attribute is ignore if @Test is not at the class level.
*/
public String testName() default "";

所以 testName 始终为空。

需要更改哪些内容才能在方法级别不忽略此属性?

我正在使用 TestNG .xml 套件来运行我的测试,如果知道这一点很重要的话。

很高兴任何提示,干杯!

【问题讨论】:

    标签: java methods annotations testng reportng


    【解决方案1】:

    在方法级别指定它是没有意义的,因为测试的名称适用于整个类。

    【讨论】:

    • 您好 Cedric,据我了解,该测试将显示在 suite.xml 中指定的名称,不是吗?我要做的基本上是“滥用” testName 属性以轻松地将某些内容传递到我的报告中。而不是创建一个新的注释/属性,我想重写 testName 的逻辑,以便即使在方法级别使用它也可以设置。谢谢!
    • 使用@Test(description = "the description of your test")怎么样?这似乎比测试名称更适合您想要的东西。顺便说一下,请随意在 testng-user 邮件列表上继续讨论。
    • 不太符合我的需要,因为我希望在 ReportNG-Report 中同时显示 testName 和 testDescription。无论如何,我已经做了一个自定义注释并根据我的需要修改了 ReportNG - 这比预期的要容易:)
    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 2017-04-30
    相关资源
    最近更新 更多