0

我正在使用 testng 编写魅力报告,并且有一个非常基本的方法,如下所示。

@Test
@DisplayName("Hello this is a description for allure report")
public void method1(){
  System.out.println("Hi i am from method1");
}

在上面的代码中,@DisplayName 来自 allure 报告。现在我想要实现的是在运行时使用 TestngListners 设置 DisplayName。

我查看了 ITextResult 和 ITestContext,但据我所知,它不支持此功能。

有没有其他方法可以实现这一目标?

4

1 回答 1

0

如果您使用的是 Junit 启动器,则只需通过迭代测试计划即可获得显示名称。

显示名称的代码如下:

testPlan.getRoots ()
            .forEach (testIdentifier -> testPlan.getChildren (testIdentifier).
                    forEach (testIdentifier1 -> testPlan.getChildren (testIdentifier1).
                            forEach (testIdentifier2 -> testCaseList.add (testIdentifier2.getDisplayName ()))));
于 2020-08-20T15:40:00.457 回答