2015-04-03 55 views
1

我需要創造一個testng``素文字幫助..如何創建TestNG的類

我已創建了一個類僅包含@beforesuite其中包含的命令來打開應用程序

@beforesuite 

和第二類包含3種方法

@test{method1} 
@test{method2} 
@test{method3} 

和第三類包含@AfterSuite其關閉應用程序...

@AfterSuite 

如何編寫一個xml文件來一個接一個地運行這些類。

有沒有更好的方法來編寫腳本?

任何建議將是有益的。

在此先感謝。

Sudhanva

回答

0

只要把這些類的測試套件文件和TestNG將運行的第一個具有@BeforeSuite的類,它有下一個@Test類,其次是它具有類的護理@ aftersuite標籤。

<suite> 
<test name ="myTest"> 
<classes> 
<class name ="Class1"/> <!-- Class with @beforeSuite--> 
<class name ="Class2"/> <!-- Class with @test--> 
<class name ="Class3"/> <!-- Class with @afterSuite--> 

</classes> 
</test> 
</suite> 

順便說一下,爲什麼你想爲@AfterSuite和@BeforeSuite方法有不同的類。如果所有人都在同一個班上,情況會更簡單。但它只是我的想法。

0

我建議如下:

  1. 請通過此link,這是TestNG的非常詳細的文檔。您可以設置Test註釋的'priority'屬性。

    //this decides the order in which your tests are executed   
    @test{priority=1} //executed first   
    @test{priority=2} //executed second   
    @test{priority=3} //executed third 
    
  2. 因爲這看起來像一個關鍵字驅動的框架,我建議你從一個Excel工作表,而不是實現XML解析器通過類名。

  3. 爲了實現excel表的讀寫,Apache POI是一個很好的庫。它支持xls和xlsx文件。這樣修改執行順序也很容易。有關關鍵字驅動框架的更多信息,請參閱此link

  4. 就報告結構而言,TestNG可以生成自己的報告,但ATU Graphical Reporter具有很好的視覺吸引力。

0

這是怎麼提到你的測試在XML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<suite name="SuiteName" verbose="1" data-provider-thread-count="10" 
    thread-count="10"> 
    <test name="TestName" thread-count="10"> 
     <classes> 
      <class name="packageName.ClassName"/> 
      <class name="packageName.ClassName" /> 
     </classes> 
    </test> 
</suite>