1. 程式人生 > >eclipse中testng的配置和使用

eclipse中testng的配置和使用

Eclipse版本:
Eclipse Java EE IDE for Web Developers.
Version: Helios Release

Testng版本:
5.13

步驟

1.Eclipse中點選Help->Install new software
2.點選Add    在Location輸入 http://beust.com/eclipse

下載testng

3.選中Testng版本,點選Next,按照提示安裝,安裝完之後重啟Eclipse
4.新建JavaProject,右鍵BuildPath,新增testng-5.11-jdk15.jar和eclipse-testng.jar
5.新建一個sum類,用來計算兩整數之和,程式碼如下:

1234567891011121314packagecom.hpp;publicclasssum{privateintno1;privateintno2;privateintmysum;publicintadd(intno1,intno2){mysum=no1+no2;returnmysum;}}

6.再新建testng class

新建class

點選finish,程式碼如下

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 packagecom.test; importorg.testng.annotations.Test; import
staticorg.testng.Assert.assertEquals; importcom.hpp.sum; publicclassNewTest{ privatesum newSum=newsum(); @Test publicvoidf(){ intmysum=newSum.add(1,2); assertEquals(3,mysum,"Right"); } }

testing,xml會自動配置好的,這裡不用管
專案的檔案結構如下:

專案結構

7.在testing.xml右鍵點選RunAs->Testng Suite,即可看到結果

執行結果

至於selenium 2 的jar包只需要直接的專案中匯入即可了