简体   繁体   中英

TestNG execution order for test groups

Say I have the following XML:

<suite name="MATS">
    <test name="mats_test">
    <groups>
        <run>
            <include name="mats" />
        </run>
    </groups>
    <packages>
        <package name="com.tests" />
    </packages>
    </test>
</suite>

And each test class in the com.tests package has only one test method with varying group annotations. Will the beforeClass() and afterClass() methods of classes not in the "mats" group be executed?

Before/After methods not in the specified group(s) will not run unless they set alwaysRun to true .

alwaysRun

For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to.

For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.

eg Given the following classes:

public class AMatsTest {
    @BeforeSuite(groups = {"mats"})
    public void beforeSuite() {}
}

public class NotAMatsTest {
    @BeforeSuite
    public void beforeSuite() {}
}

@Test(groups = {"mats"})
public class AnotherMatsTest {
    @BeforeSuite public void beforeSuite() {}
}

public class AlwaysTest {
    @BeforeSuite(alwaysRun = true)
    public void beforeSuite() {}
}

AMatsTest.beforeSuite() , AnotherMatsTest.beforeSuite() , and AlwaysTest.beforeSuite() will be executed. NotAMatsTest.beforeSuite() will not be executed.

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