您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > TestNG
持续集成:TestNG中case之间的关系
作者:网络转载 发布时间:[ 2016/1/15 15:25:01 ] 推荐标签:单元测试 软件测试工具

  我们写培训单元测试,写case代码的时候,可能会遇到一条case依赖另外一条case,比如我现在用一个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所在的组,这样当该case执行的时候,被依赖组中的case都会被执行。而我只是给groups定义为androidtestresult,所以androidtestresult组中只有一条case为generateAndroidXmlTestResult,所以只会执行这条case。
  执行结果:
[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@3c6210fbcase1=com.wuba.result.TestCaseLoop@4a48edb5case2=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@67e13e07case2=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@4b1c2b67case5=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@3d3cdaacase9=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@5421e554case8=com.wuba.result.TestCaseLoop@7d5718f2case9=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

软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd