持续集成:TestNG中case之间的关系

持续集成:TestNG中case之间的关系

 

poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-84505200。

我们写培训单元测试,写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@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@661736e, case1=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@26659db7, case6=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@1a0fced4, case8=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

上一篇:阿里云OSS上传文件demo


下一篇:NuGet管理