![](/img/trans.png)
[英]How to run tests in parallel by methods with TestNG and Selenium
[英]How to run Selenium Java tests with TestNG programmatically?
我正在使用Selenium RC和Java,使用TestNG作為測試框架。 我正在使用Eclipse作為IDE。 我想很容易地從我自己的程序中調用TestNG。 我怎樣才能做到這一點?
我在java中的以下代碼很好地工作:
@Test
public void testTestNGProgramatically(){
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] {LoginAuthentication.class, GmailSigninSignout.class});
testng.addListener(tla);
testng.run();
}
您可以訪問以下網址獲取詳細信息說明:
http://testng.org/doc/documentation-main.html#running-testng-programmatically
雖然TestMethodWorker()是內部的,所以你不應該使用它,但是提供了一些很好的指導。
基於這個問題,我甚至不確定原始海報是否試圖在單獨的流程中啟動TestNG,因此API文檔可能正是您所尋找的:
http://testng.org/doc/documentation-main.html#running-testng-programmatically
看看org.testng.remote.RemoteTestNG,但是這需要你為你的測試編寫一個xml套件,如:
<suite name="Default suite">
<test verbose="2" name="Default test">
<classes>
<class name="com...service.UserServiceImplTest"/>
</classes>
</test>
</suite>
另一個入口點可能是新的org.testng.internal.TestMethodWorker(...)。run()但你必須查看代碼以確定你需要設置的構造函數args。
也許根據您的需要,可以使用其他更方便的入口點; 我建議在調試模式下啟動一些測試,在測試中放置一個斷點並向下移動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.