I have a base class that represents a database test in TestNG, and I want to specify that all classes extending from this class are of a group "db-test", however I have found that this doesn't seem possible. I have tried the @Test annotation:
@Test(groups = { "db-test" })
public class DBTestBase {
}
However, this doesn't work because the @Test annotation will try to make a bunch of methods into tests, and warnings/errors pop up in eclipse when the tests are run.
So I tried disabling the test, so at least the groups are assigned:
@Test(enabled = false, groups = { "db-test" })
public class DBTestBase {
}
but then any @BeforeTest (and other similar annotations) ALSO get disabled... which is of course not what I want.
I would like some way to annotate a class as being of a particular type of group, but it doesn't quite seem possible in TestNG. Does anyone have any other ideas?
Groups in TestNG are specified in testng. xml under the <suite> or <test> tag. Groups under the <suite> tag apply to all the tests included under the <test> tag in that particular <suite>. To group tests in the source code, you have to use the @groups attribute of the @Test annotation.
We can combine multiple groups to single Test in TestNG with the help of test group feature.
Users can group multiple tests into a named group. The user can execute a particular set of tests belonging to a group or multiple groups. The test grouping feature allows the tests to be segregated into different sections or modules.
The Complete TestNG & Automation Framework Design CourseThere are no specific ways to exclude a class in <classes>, but there are workarounds that are quite useful in case you don't want to run a specific class in a testing suite. Following are some of the handy ways to exclude a test class run from a test suite.
TestNG will run all the public methods from a class with a @Test annotation. Maybe you could change the methods you don't want TestNG to run to be non-public
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With