? TestNG是java的一個測試框架,相比較于junit,功能更強大和完善,我是直接學(xué)習(xí)和使用的TestNG就來談下TestNG的一些特點吧。
?TestNG的特點
注解
TestNG使用Java和面向?qū)ο蟮墓δ?/p>
支持綜合類測試(例如,默認情況下,沒有必要創(chuàng)建一個新的測試每個測試方法的類的實例)
獨立的編譯時間測試代碼運行時配置/數(shù)據(jù)信息
靈活的運行時配置
主要介紹“測試組”。當(dāng)編譯測試,只要問TestNG運行所有的“前端”的測試,或“快”,“慢”,“數(shù)據(jù)庫”等
支持依賴測試方法,并行測試,負載測試,局部故障
靈活的插件API
支持多線程測試
TestNG注解

TestNG的執(zhí)行
? ??TestNG有兩種執(zhí)行的方法:
? ? 一種是選擇右鍵要執(zhí)行的方法,點Run As ->TestNG Test;
? ? 另外一種是通過testng.xml文件來執(zhí)行. 把要執(zhí)行的case, 放入testng.xml文件中。 右鍵點擊testng.xml, ? 點Run As。
? ? 但其實第一種執(zhí)行的方法也是eclipse默認創(chuàng)建了xml文件執(zhí)行,文件的地址在執(zhí)行結(jié)果中就有。
TestNG簡單例子
package com.testngDemo;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;publicclass DemoTestng {
? ? @BeforeClass
? ? publicvoid setup()
? ? {
? ? ? ? System.out.println("begin test");
? ? }
? ? @Test
? ? publicvoid test()
? ? {
? ? ? ? System.out.println("at test");
? ? }
? ? @AfterClass
? ? publicvoid teardown()
? ? {
? ? ? ? System.out.println("end test");
? ? }
}
執(zhí)行代碼:

查看結(jié)果:

我們可以在結(jié)果中看到xml文件的位置,?測試報告位于 "test-output" 目錄下。
