Quick revision
The short answer
A reliable taxonomy has a few well-defined groups by purpose and cost, such as unit, integration and e2e, with smoke as an extra label, and keeps ownership separate, through the package or a dedicated owner tag. It avoids groups that encode environments or ticket numbers, enforces with a listener or build check that every test has exactly one cost group, maps each pipeline stage to groups with a time budget, and reviews usage regularly so unused groups are deleted.
What to remember
In this answer, we designed a group taxonomy that a pipeline can rely on: exactly one cost group per test, unit, integration or e2e, with clear definitions, plus a few purpose labels such as smoke and quarantine, and ownership expressed through packages or an owner annotation. We avoided environment and ticket groups, enforced the rules with a shared listener, mapped each pipeline stage to groups with a time budget, and planned a regular review that deletes unused groups.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A reliable taxonomy has a few well-defined groups by purpose and cost, such as unit, integration and e2e, with smoke as an extra label, and keeps ownership separate, through the package or a dedicated owner tag. It avoids groups that encode environments or ticket numbers, enforces with a listener or build check that every test has exactly one cost group, maps each pipeline stage to groups with a time budget, and reviews usage regularly so unused groups are deleted.
Why this question is asked
Groups are the interface between the test code and the CI pipeline. The pipeline says run the integration tests now, and it trusts the labels to mean the same thing in every team's code. With one team that trust is easy; with ten teams writing tests in the same suite, labels drift within months: one team's integration is another's component, someone adds a group per sprint, and a stage that should take 10 minutes suddenly takes 40. Interviewers ask this design question to see whether we can design labels that a machine can rely on. In this answer, we will recap what groups do, define the cost groups, add the extra labels and ownership, look at what to avoid, enforce the rule in the build, map the groups to pipeline stages, and plan the review.
1A Quick Recap of Groups as a Selection Mechanism
In TestNG, @Test(groups = ...) attaches string labels to a test method or class, and a run can include and exclude groups through testng.xml, Maven Surefire's groups and excludedGroups, or Gradle's includeGroups and excludeGroups. A test runs if it is in an included group and in no excluded group. TestNG does not care what the strings mean; the meaning comes entirely from our conventions. That is why a taxonomy, a small agreed set of labels with definitions, is needed as soon as more than one team writes tests.
2The Core: One Cost Group Per Test
The labels that pipelines rely on most should describe what a test needs and therefore how much it costs. We define three, with rules a reviewer can check. unit: no network, no database, no file system beyond temporary files, no Spring context; typically a few milliseconds. integration: real infrastructure started for the test, such as a database or Kafka in a container, or a Spring context with its web layer; typically under a few seconds each. e2e: a deployed system, usually through its public API or a browser; seconds to minutes each.
Every test belongs to exactly one of these. The reason for exactly one is that the pipeline uses them to split work, and a test that is in none never runs, while a test in two runs twice and blurs the time budgets.
| Group | Kind | Definition | Rule |
|---|---|---|---|
| unit | cost | No network, database or Spring context | Exactly one cost group per test |
| integration | cost | Real infrastructure in containers or a Spring context | Exactly one cost group per test |
| e2e | cost | Deployed system through API or browser | Exactly one cost group per test |
| smoke | purpose | Few critical checks after deployment | Optional, on top of a cost group |
| quarantine | status | Flaky, owned, with a deadline | Optional, non-blocking |
3Extra Labels and Ownership
On top of the cost group, a test may carry a small number of purpose labels. smoke marks the handful of checks that prove a deployment works, often 20 to 50 tests out of thousands, and it is always combined with a cost group, usually e2e. quarantine marks flaky tests that are temporarily non-blocking, each with an owner and a deadline.
Ownership is a different question and should not be mixed into the groups. If we create groups like team-payments, a test's groups now carry two meanings, and selection expressions become hard to read. Ownership is better expressed by the package, such as com.shop.payments, mapped to a team in a CODEOWNERS-style file, or by a separate annotation such as @Owner("payments") that reporting tools read. Then reports can show failures by team without changing what the pipeline runs.
4What Not to Encode in Groups
Two kinds of groups rot quickly. The first is environment groups, such as staging or uat. Which environment a test runs against is a property of the run, supplied by configuration, not a property of the test; tagging tests with it leads to duplicated tests and to suites that silently skip half their checks in a new environment. The second is ticket or release groups, such as JIRA-4211 or release-7. They make sense for a week and then remain forever, and nobody knows whether they can be removed. A good test of a proposed group is whether its meaning will be the same in a year.
5Enforcing the Taxonomy in the Build
Conventions that are not checked drift. We enforce the rule with a listener in the shared test library: before the suite runs, it checks each test method's groups against the allowed set and fails the run with a clear list of violations.
Notice that the check catches both a missing cost group and an unknown label, which is how typos like integraton show up. Because the listener is part of the shared library, every team gets it automatically, and introducing a new group means changing the library, which forces a conversation. A similar check can be written for JUnit Jupiter tags with ArchUnit or a JUnit Platform listener.
6Mapping Pipeline Stages to Groups
With reliable labels, each pipeline stage becomes a simple selection with a time budget. The commit stage runs unit with a budget of, say, 5 minutes. The pull request stage runs integration, sharded, within 15 minutes. After deployment to a test environment, the pipeline runs smoke first, within 3 minutes, and then the rest of e2e. quarantine runs in a separate, non-blocking job. Each stage has its own timeout, so a stage that grows past its budget fails loudly instead of slowly eating everyone's time.
We document this mapping in one place, next to the pipeline definition, so a new team can see which of its tests will run where. Finally, we review the groups every quarter: counts per group, time per stage, and any label that no test uses any more, which we delete from the allowed set.
- Commit: unitbudget 5 min
- Pull request: integration, shardedbudget 15 min
- Deploy to test environmentconfiguration supplies the URL
- Smoke: smoke and e2ebudget 3 min, blocks promotion
- Full e2e excluding smokebudget 30 min
- Quarantine jobnon-blocking, reported to owners
6 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Should smoke tests be a separate cost group?
No. Smoke describes purpose, not cost: a smoke check is usually an e2e test that happens to be critical. Keeping it as an extra label means smoke tests still count towards the e2e budget and run in the full e2e stage, and the smoke stage can select them precisely with smoke as the include.
How do you migrate an existing suite with messy groups?
Run the listener in reporting mode first, so it logs violations without failing. Publish the counts per team, provide a script that suggests a cost group from simple signals, such as whether the class starts a Spring context or uses a container, and set a date after which the listener enforces. Old groups are mapped or deleted in the same period.
What about a group for tests that need a specific feature flag?
That is usually configuration, not a group. The test should set the flag it needs, or read it from the test configuration and skip itself explicitly with a clear reason if the environment cannot provide it. A group for it would spread the knowledge of environments into test labels, which is exactly what rots.
8Conclusion
In this answer, we designed a group taxonomy that a pipeline can rely on: exactly one cost group per test, unit, integration or e2e, with clear definitions, plus a few purpose labels such as smoke and quarantine, and ownership expressed through packages or an owner annotation. We avoided environment and ticket groups, enforced the rules with a shared listener, mapped each pipeline stage to groups with a time budget, and planned a regular review that deletes unused groups.
Open with
I would keep the taxonomy small and make one part of it mandatory. Every test gets exactly one cost group: unit, integration or e2e, each with a definition a reviewer can check.
Then, if they want more
Unit means no network, database or Spring context. Integration means real infrastructure started for the test, like a database in a container or a Spring context. E2e means a deployed system through its API or a browser. Exactly one, because the pipeline splits work by these groups: a test in none never runs and a test in two runs twice.
On top of that, a couple of purpose labels: smoke for the few critical post-deployment checks, and quarantine for flaky tests with an owner and a deadline. Ownership I keep out of groups; it comes from the package or a separate owner annotation, so reports can show failures by team without changing selection.
I would explicitly avoid groups for environments, because the environment is configuration of the run, and groups for tickets or releases, because they are never cleaned up. To make it stick, the shared test library includes a listener that fails the run if a test has no cost group, more than one, or an unknown label.
Then the pipeline maps stages to groups, unit on commit, integration on pull requests, smoke then e2e after deployment, each with its own timeout. And every quarter we review counts and time per group and delete labels nobody uses.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Define a group taxonomy for a TestNG suite used by 10 teams so that the CI pipeline can...": https://scrivio-interview-library.netlify.app/java/testng/d18f23a4b0/