Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I specify a class wide group on a TestNG test case?

Tags:

java

testng

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?

like image 251
Mike Stone Avatar asked Aug 12 '08 16:08

Mike Stone


People also ask

How do I specify groups in TestNG?

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.

Can we assign multiple groups to a test case?

We can combine multiple groups to single Test in TestNG with the help of test group feature.

Can we group more than one in TestNG?

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.

Can we exclude class in TestNG?

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.


1 Answers

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

like image 156
Alejandro Bologna Avatar answered Oct 19 '22 03:10

Alejandro Bologna