When we write a unit test, we may encounter a case that relies on a different instance, for example, I now generate an HTML file with an XML file, but this XML file is generated by a different one. So we need to define a dependency that generates the HTML case to be generated after the case of the XML file is generated, and see what is the solution dependsongroups
The single test case for generating XML is as follows:
@Test (groups = {"UnitTest", "Androidtestresult"})
The single test case for generating HTML is as follows:
@Test (groups = {"UnitTest"}, dependsongroups = {"Androidtestresult"})
The dependsongroups attribute is defined on the case on which dependency is required, which is the group of dependent cases, so that when it is executed, the box in the dependent group is executed. And I'm just defining groups as Androidtestresult, so only one case in the Androidtestresult group is Generateandroidxmltestresult, so the case will only be executed.
Execution results:
[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/Do cuments/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-te Stresult [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 XmlReportGenerat Or: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/sour Cecode/self/responsetimetool/repo/report/2015-07-31_12-21-10/testreport.xml 2015-07-31 12:21:10 INFO htmlreportgenerator:95-created the 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.rep Orters.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.re Porters.
Junitreportreporter@47d62270:5 ms
But this means that there is only one case in the group you are relying on, which is not very good, so let's find out if we can rely directly on a single case.