您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > TestNG
持續(xù)集成:TestNG中case之間的關(guān)系
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2016/1/15 15:25:01 ] 推薦標(biāo)簽:單元測試 軟件測試工具

  我們寫培訓(xùn)單元測試,寫case代碼的時候,可能會遇到一條case依賴另外一條case,比如我現(xiàn)在用一個xml文件生成html文件,但是這個xml文件是另外一條case生成的。所以我們需要定義一種依賴是生成html的case要在生成xml文件的case之后生成,看看有什么解決的方法
  dependsOnGroups
  生成xml的單測case如下:
  @Test(groups = { "unittest","androidtestresult" })
  public void generateAndroidXmlTestResult()
  生成html的單測case如下:
  @Test(groups = { "unittest" }, dependsOnGroups = { "androidtestresult" })
  public void generatorAndroidReportByMuiltDirTest()
  在需要依賴的case上定義了dependsOnGroups屬性,里面是被依賴case所在的組,這樣當(dāng)該case執(zhí)行的時候,被依賴組中的case都會被執(zhí)行。而我只是給groups定義為androidtestresult,所以androidtestresult組中只有一條case為generateAndroidXmlTestResult,所以只會執(zhí)行這條case。
  執(zhí)行結(jié)果:
[TestNG] Running:
/private/var/folders/3j/s3hfvmy572vcn3h02c_rxcbm0000gn/T/testng-eclipse-774643464/testng-customsuite.xml
2015-07-31 12:21:10 INFO  TestResult:156 - Created testResult.xml  file at file:///Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/MI_2G_dksldfdffdf_4.4.2_201507210823923/testResult.xml
2015-07-31 12:21:10 INFO  TestResult:93 - TestResult [rootDir=/Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/MI_2G_dksldfdffdf_4.4.2_201507210823923, loops={case3=com.wuba.result.TestCaseLoop@3c6210fb, case1=com.wuba.result.TestCaseLoop@4a48edb5, case2=com.wuba.result.TestCaseLoop@79ee2c2c}, device=MI, network=2G, sn=dksldfdffdf, version=4.4.2]
2015-07-31 12:21:10 INFO  XmlReportGenerator:108 - Read testResult.xml finished
2015-07-31 12:21:10 INFO  XmlReportGenerator:109 - TestResult [rootDir=/Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/MI_2G_dksldfdffdf_4.4.2_201507210823923, loops={case3=com.wuba.result.TestCaseLoop@661736ecase1=com.wuba.result.TestCaseLoop@67e13e07, case2=com.wuba.result.TestCaseLoop@74af72d8}, device=MI, network=2G, sn=dksldfdffdf, version=4.4.2]
2015-07-31 12:21:10 INFO  XmlReportGenerator:108 - Read testResult.xml finished
2015-07-31 12:21:10 INFO  XmlReportGenerator:109 - TestResult [rootDir=/Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/MI_3G_dksldfdffdf_4.4.2_20150721082392, loops={case4=com.wuba.result.TestCaseLoop@4b1c2b67, case5=com.wuba.result.TestCaseLoop@26659db7case6=com.wuba.result.TestCaseLoop@59556d12}, device=MI, network=3G, sn=dksldfdffdf, version=4.4.2]
2015-07-31 12:21:10 INFO  XmlReportGenerator:108 - Read testResult.xml finished
2015-07-31 12:21:10 INFO  XmlReportGenerator:109 - TestResult [rootDir=/Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/MI_4G_dksldfdffdf_4.4.2_20150721082392, loops={case7=com.wuba.result.TestCaseLoop@1a0fced4case8=com.wuba.result.TestCaseLoop@3d3cdaa, case9=com.wuba.result.TestCaseLoop@466355dc}, device=HW, network=4G, sn=1232324343, version=4.4.2]
2015-07-31 12:21:10 INFO  XmlReportGenerator:108 - Read testResult.xml finished
2015-07-31 12:21:10 INFO  XmlReportGenerator:109 - TestResult [rootDir=/Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/result/android/HW_4G_12323242_4.4.2_20150721082392, loops={case7=com.wuba.result.TestCaseLoop@5421e554, case8=com.wuba.result.TestCaseLoop@7d5718f2, case9=com.wuba.result.TestCaseLoop@6126f827}, device=MI, network=4G, sn=dksldfdffdf, version=4.4.2]
2015-07-31 12:21:10 INFO  TestReport:78 - Created file at file:///Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/report/2015-07-31_12-21-10/testReport.xml
2015-07-31 12:21:10 INFO  HtmlReportGenerator:95 - Created report html file at file:///Users/wuxian/Documents/sourcecode/self/ResponseTimeTool/repo/report/2015-07-31_12-21-10/testReport.html
PASSED: generateAndroidXmlTestResult
PASSED: generatorAndroidReportByMuiltDirTest
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.jq.Main@fcfa52: 31 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@388ee016: 7 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@351563ff: 3 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@220ca470: 9 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@47d62270: 5 ms

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