我正在開發一個項目,我需要以編程方式調用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