简体   繁体   中英

TESTNG Consistent execution of the test groups

Сreated methods:

@BeforeGroups(groups = {"INdependent"})
@BeforeGroups(groups = {"dependent"})
@Test (groups = {"INdependent"})
@Test (groups = {"dependent"}, dependsOnGroups = {"INdependent"})
@AfterMethod(groups = {"INdependent"})
@AfterMethod(groups = {"dependent"})
@AfterGroups(groups = {"INdependent"})
@AfterGroups(groups = {"dependent"})

Expected:

- BeforeGroups = "INdependent"
 - Test = "INdependent"
 - AfterMethod = "INdependent"
- AfterGroups = "INdependent"
- BeforeGroups = "dependent"
 - Test = "dependent"
 - AfterMethod = "dependent"
- AfterGroups = "dependent"

Actual:

- BeforeGroups = "INdependent"
 - Test = "INdependent"
 - AfterMethod = "dependent"     (этого тут быть не должно)
 - AfterMethod = "INdependent"
- AfterGroups = "INdependent"
- BeforeGroups = "dependent"
 - Test = "dependent"
 - AfterMethod = "dependent"
 - AfterMethod = "INdependent"   (этого тут быть не должно)
- AfterGroups = "dependent"

What am I doing wrong?

testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
  <test name="mts-sorm3-extractor-tests">
   <groups>
       <run>
           <include name="independent"/>
           <include name="dependent"/>
       </run>
    </groups>
    <classes>
      <class name="ru.mts.sorm.mts_sorm3_extractor_tests.Sorm3ExtractDictTest"/>
    </classes>
  </test> <!-- mts-sorm3-extractor-tests -->
</suite> <!-- Custom suite -->

Groups are used for tests selection. When you ask for independent and dependent groups then all methods with one of this 2 groups will be run.

That's why @AfterMethod(groups = {"INdependent"}) and @AfterMethod(groups = {"dependent"}) are called for every test methods of the class.

The good solution will be to move independent test in a class and dependent in another class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM