Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 75871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:35:02+00:00 2026-05-10T20:35:02+00:00

I have a base class that represents a database test in TestNG, and I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:35:03+00:00Added an answer on May 10, 2026 at 8:35 pm

    The answer is through a custom org.testng.IMethodSelector:

    Its includeMethod() can exclude any method we want, like a public not-annotated method.

    However, to register a custom Java MethodSelector, you must add it to the XMLTest instance managed by any TestRunner, which means you need your own custom TestRunner.

    But, to build a custom TestRunner, you need to register a TestRunnerFactory, through the -testrunfactory option.

    BUT that -testrunfactory is NEVER taken into account by TestNG class… so you need also to define a custom TestNG class :

    • in order to override the configure(Map) method,
    • so you can actually set the TestRunnerFactory
    • TestRunnerFactory which will build you a custom TestRunner,
    • TestRunner which will set to the XMLTest instance a custom XMLMethodSelector
    • XMLMethodSelector which will build a custom IMethodSelector
    • IMethodSelector which will exclude any TestNG methods of your choosing!

    Ok… it’s a nightmare. But it is also a code-challenge, so it must be a little challenging 😉

    All the code is available at DZone snippets.

    As usual for a code challenge:

    • one java class (and quite a few inner classes)
    • copy-paste the class in a ‘source/test’ directory (since the package is ‘test’)
    • run it (no arguments needed)

    Update from Mike Stone:

    I’m going to accept this because it sounds pretty close to what I ended up doing, but I figured I would add what I did as well.

    Basically, I created a Groups annotation that behaves like the groups property of the Test (and other) annotations.

    Then, I created a GroupsAnnotationTransformer, which uses IAnnotationTransformer to look at all tests and test classes being defined, then modifies the test to add the groups, which works perfectly with group exclusion and inclusion.

    Modify the build to use the new annotation transformer, and it all works perfectly!

    Well… the one caveat is that it doesn’t add the groups to non-test methods… because at the time I did this, there was another annotation transformer that lets you transform ANYTHING, but it somehow wasn’t included in the TestNG I was using for some reason… so it is a good idea to make your before/after annotated methods to alwaysRun=true… which is sufficient for me.

    The end result is I can do:

    @Groups({ 'myGroup1', 'myGroup2'}) public class MyTestCase {     @Test     @Groups('aMethodLevelGroup')     public void myTest() {     } } 

    And I made the transformer work with subclassing and everything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems to me that Product in the context of… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Hmmm... I'm not an iPhone developer, but.... Could you try… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer ttyname(0) will return the filename of the current terminal associated… May 11, 2026 at 11:34 pm

Related Questions

If I have a table in MySQL which represents a base class, and I
I am working on a Web Forms application and I have some HTML code
I want to create a product catalog that allows for intricate details on each
In an application similar to StackOverflow that I am building, I am trying to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.