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

Question :

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

Answer :

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.

Read More  Looking for best practice for doing a “Net Use” in C#

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?


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

Read More  How to dispose a class in .net?

That’s the answer Can I specify a class wide group on a TestNG test case?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you