Reputation: 489
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?
Upvotes: 1
Views: 924
Reputation: 31274
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.
e.g. 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.
Upvotes: 1