我正在开发一个项目,我需要以编程方式调用TestNG(使用数据提供程序)。事情没有问题,只是在报告中,我们得到了@Test方法的名称,这是处理大量情况的通用方法。我们想要的是在报告中获得一个有意义的名字。TestNG报告中的自定义测试方法名称
我在这方面正在研究并找到3种方法,但不幸的是,对我来说都是失败的。
1)实施ITEST
我设置我,只要我进入@Test方法(对于所有3种方式,我试图想要的名字,这是我设置名称的方式)。该名称从getTestName()返回。我观察到的是getTestName()在我的@Test之前和之后被调用。最初,它返回null(用于处理NullPointerException,我返回“”而不是null),然后它返回正确的值。但我没有看到这个越来越反映在报告中
编辑:也尝试设置从@ BeforeMethod名称由artdanil的建议
2和3
两者都是基于给定的解决方案在second link above
通过XmlSuite覆盖的setName,我越来越
Exception in thread "main" java.lang.AssertionError: l should not be null
at org.testng.ClassMethodMap.removeAndCheckIfLast(ClassMethodMap.java:58)
at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:208)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
...
通过覆盖的toString(),我看到这些日志中(有我的评语),但报告没有更新
[2013-03-05 14:53:22,174] (Main.java:30) - calling execute
[2013-03-05 14:53:22,346] GenericFunctionTest.<init>(GenericFunctionTest.java:52) - inside constructor
[2013-03-05 14:53:22,372] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning **//this followed by 3 invocations before arriving at @Test method**
[2013-03-05 14:53:22,410] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning
[2013-03-05 14:53:22,416] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning
[2013-03-05 14:53:22,455] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning
[2013-03-05 14:53:22,892] GenericFunctionTest.<init>(GenericFunctionTest.java:52) - inside constructor
[2013-03-05 14:53:23,178] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning **//again blank as i havent set it yet**
[2013-03-05 14:53:23,182] GenericFunctionTest.getResult(GenericFunctionTest.java:69) - inside with test case:TestCase{signature=Signature{...}}**//I am setting it immedietely after this**
[2013-03-05 14:53:23,293] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning MyMethodName **//What i want**
[2013-03-05 14:53:23,299] GenericFunctionTest.toString(GenericFunctionTest.java:276) - returning MyMethodName **// again**
编辑:再次被硬编码的值,而不是把它放在入境尝试了所有3我的测试方法。但相同的结果
我使用TestNG的报表监听器来触发建立我的HTML出的iSuite结果的类做到这一点。要显示测试报告中的任意数据(例如测试参数值),我认为您必须为每个测试的ITestContext添加数据,以便报告编写者可以访问其他数据。幸运的是,方法名称已经是该上下文的一部分,您可以检索它。 – djangofan 2014-01-22 23:01:25