您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > TestNG
TestNg測(cè)試框架使用
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/10/28 15:26:55 ] 推薦標(biāo)簽:單元測(cè)試

  配置TestNg suite
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<!--enabled="true"讓測(cè)試生效,也可根據(jù)情況關(guān)閉某些測(cè)試 -->
<test name="Test" enabled="true">
<!--指定參數(shù) -->
<parameter name="Name" value="Irving" />
<parameter name="Sex" value="Man" />
<!--指定測(cè)試包 -->
<packages>
<package name="com.homeinns.web.testng.*" />
</packages>
<!--指定測(cè)試類(lèi) -->
<classes>
<class name="com.homeinns.web.testng.AppTest" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
TestNg注解配置
public class NgTest {
@Test
public void f() {
}
@Test(
// 在指定的時(shí)間內(nèi)啟用3個(gè)線程并發(fā)測(cè)試本方法10次
threadPoolSize = 3, invocationCount = 10, timeOut = 10000,
// 等待測(cè)試方法t0測(cè)試結(jié)束后開(kāi)始本測(cè)試
dependsOnMethods = { "f" },
// 指定測(cè)試數(shù)據(jù)源CLASS和數(shù)據(jù)源名稱(參考注解@DataProvider),返回幾條數(shù)據(jù)會(huì)跑測(cè)試方法幾次
dataProvider = "generate", dataProviderClass = GeneratorRandomNum.class,
// 分組名稱
groups = { "checkin-test" })
// 讀取配置文件中的參數(shù),配置如上,用@Optional設(shè)置默認(rèn)值
@Parameters({ "Name" })
public void f1(@Optional("name") String name) {
}
}
  測(cè)試報(bào)告
  運(yùn)行測(cè)試后 在my-testng/test-output/ 目錄下(maven argetsurefire-reports)
  gradle配置
subprojects {
apply plugin: 'java'
// Disable the test report for the individual test task
test {
reports.html.enabled = false
}
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
//Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}Grouping TestNG tests
test {
useTestNG {
excludeGroups 'integrationTests'
includeGroups 'unitTests'
}
}

上一頁(yè)12下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd