Quick revision
The short answer
We define a test portfolio: fast checks on every commit, broader checks before merge, and long suites nightly or before release, with selection by risk through test impact analysis, changed modules and a set of critical journeys that always run. Product teams own their tests, a platform team owns the pipeline and the selection tooling, and the policy itself is agreed with engineering leadership. We delete low-value tests and track defect escape rates to prove that selection does not miss bugs; groups and tags are only the mechanism.
What to remember
In this answer, we replaced an implicit, ad hoc choice of tests with an explicit portfolio of stages, each with a purpose and a budget, selected tests by risk with impact analysis, the module graph and an always-run list of critical journeys, and split ownership between product teams, a platform team and engineering leadership. We kept the suite healthy by pruning low-value tests, verified selection with the defect escape rate, and treated groups and tags as the mechanism that implements the policy.
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.
We define a test portfolio: fast checks on every commit, broader checks before merge, and long suites nightly or before release, with selection by risk through test impact analysis, changed modules and a set of critical journeys that always run. Product teams own their tests, a platform team owns the pipeline and the selection tooling, and the policy itself is agreed with engineering leadership. We delete low-value tests and track defect escape rates to prove that selection does not miss bugs; groups and tags are only the mechanism.
Why this question is asked
When a suite becomes too large to run before every release, the organisation has already started making choices about what to skip; it is just making them implicitly, by timeouts, by habit, or by whoever is in a hurry. Interviewers ask this leadership question to see whether we can turn that into an explicit, owned policy that balances speed and risk, and whether we understand that the technical tools, TestNG groups, JUnit tags, test impact analysis, only implement a decision people must make. In this answer, we will describe the portfolio of stages, explain how tests are selected by risk, settle ownership, look at how we prune and verify, and finish with how we would introduce the policy.
1The Situation in Numbers
Consider a company with 40,000 automated tests across many services. Run end to end on one pipeline, they take 14 hours, so nobody runs all of them before a release. Teams pick what they think matters, and every few weeks a defect reaches production that a test in the unrun part would have caught. The goal is not to run everything all the time, which is impossible, but to make sure the right tests run at the right point, and to know when that choice failed.
2A Portfolio of Stages
We start by defining where tests run and what each stage is for. On every commit, fast checks give a developer feedback within minutes: unit tests and static analysis for the changed modules. Before merge, broader checks protect the main branch: integration and contract tests for the changed modules and their dependents, plus the critical journeys. Nightly, the full integration and end-to-end suites run against a production-like environment. Before release, a defined release suite runs, including the critical journeys, the full end-to-end suite of the services being released, and any long-running checks such as performance and migration tests.
Each stage has a purpose, a time budget and an owner, and the mapping from tests to stages is done with labels: TestNG groups or JUnit tags such as unit, integration, e2e and critical.
| Stage | What runs | Budget | Purpose |
|---|---|---|---|
| Every commit | Unit tests of changed modules | 5 min | Fast developer feedback |
| Before merge | Integration, contract, critical journeys for impact | 20 min | Protect the main branch |
| Nightly | Full integration and e2e suites | 3 hours | Catch what selection missed |
| Before release | Release suite of the released services | 2 hours | Release decision |
3Selecting Tests by Risk
Inside each stage, we choose by risk rather than by habit. Test impact analysis, which maps each test to the code it exercises, lets the merge stage run only the tests affected by the changed files. A simpler and very effective version uses the build's module graph: a change to the billing module runs billing's tests and those of every module that depends on billing. On top of that, a short list of critical journeys, such as sign up, pay and refund, always runs at every stage after commit, whatever changed, because their failure would be most costly.
The reason for the always-run list is that impact analysis can miss changes that the code graph does not see, such as configuration, database schema or feature flags. The critical journeys are a cheap insurance against exactly those blind spots.
4Who Owns What
Ownership has three layers, and confusing them is the usual reason such policies fail. Product teams own their tests: they write them, keep them fast and stable, label them correctly and fix or delete them when they fail. A platform or developer-productivity team owns the pipeline and the selection tooling: the stages, the impact analysis, the dashboards and the shared test libraries. The policy itself, meaning what must run before a release and what risk we accept, is a quality decision agreed with engineering leadership, written down and reviewed, not something either team decides alone.
This split matters because the platform team cannot judge which tests matter for payments, and the payments team cannot be asked to build selection tooling. Leadership owns the trade-off between speed and risk, because that trade-off affects the business.
- Engineering leadershipquality policy: what must run, accepted risk
- Platform teampipeline stages, selection tooling, dashboards
- Product teamstheir tests, labels, fixes and deletions
- Labels: groups and tagsthe mechanism that connects tests to stages
4 layers, from the top down. Step through them one at a time.
5Pruning and Verifying the Choice
A policy that only adds tests will hit the same wall again. So the portfolio comes with pruning: each quarter, teams review tests that have not failed for a year and duplicate what another test covers, tests that are slow for their value, and tests in quarantine past their deadline. Deleting a 3-minute end-to-end test that repeats a unit test's check is a gain, not a loss.
To know whether selection is safe, we track the defect escape rate: defects found in nightly or release runs that the merge stage should have caught, and defects found in production that an existing but unrun test would have caught. If the merge stage misses fewer than one defect per hundred merges and production escapes do not rise, the policy is working. If they rise, we widen selection or add to the always-run list.
6Introducing the Policy
We would introduce it in steps. First, publish the current state: test counts and times per team and the incidents of the last six months that tests could have caught. Second, agree the portfolio and the always-run journeys with leadership and team leads. Third, let the platform team roll out labels and module-graph selection, with the full suite still running nightly as the safety net. Finally, review the escape rate monthly for the first quarter and quarterly after that. Each step produces evidence that the next one builds on.
7Follow-up questions
What if a team disagrees with what runs before release?
They can propose a change to the policy with data, for example a class of defects that escaped or a stage that wastes time, and the change is decided in the same forum that agreed the policy. What they should not do is change the selection quietly in their own pipeline, because then the organisation loses the shared picture of what was verified.
How do you choose the critical journeys?
From business impact and incident history. We ask product and support which failures would hurt customers or revenue most, and check which flows caused incidents recently. The list should stay short, perhaps 10 to 20 journeys, so it can run everywhere quickly; a long list loses its point.
Is test impact analysis worth building in-house?
Usually not at first. The module graph from Maven or Gradle gives most of the benefit with little effort, and many CI products offer impact analysis. A custom tool is worth it only when the codebase is large enough that the module graph selects too much, and then the escape-rate data shows whether it pays off.
8Conclusion
In this answer, we replaced an implicit, ad hoc choice of tests with an explicit portfolio of stages, each with a purpose and a budget, selected tests by risk with impact analysis, the module graph and an always-run list of critical journeys, and split ownership between product teams, a platform team and engineering leadership. We kept the suite healthy by pruning low-value tests, verified selection with the defect escape rate, and treated groups and tags as the mechanism that implements the policy.
Open with
First I would make the choice explicit, because when nobody can run everything, people are already choosing what to skip, just without a policy. I would define a portfolio of stages: fast unit tests of the changed modules on every commit, broader integration, contract and critical journey tests before merge, the full integration and end-to-end suites nightly, and a defined release suite before each release.
Then, if they want more
Inside the stages I would select by risk: the module graph or test impact analysis picks the tests affected by a change, and a short list of critical journeys like sign up, pay and refund always runs, because impact analysis cannot see things like configuration or schema changes.
For ownership, product teams own their tests, including labelling and deleting them, a platform team owns the pipeline and the selection tooling, and the policy itself, what must run before a release and what risk we accept, is agreed with engineering leadership, because it is a business trade-off. Groups and tags are just how the pipeline implements it.
To keep it honest I would track the defect escape rate, defects caught nightly that the merge stage missed and production defects an unrun test would have caught, and prune low-value tests every quarter. If escapes rise, we widen selection; if they stay low, we keep the speed.
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 "Test suites grew to the point where nobody can run all tests before a release. How do...": https://scrivio-interview-library.netlify.app/java/testng/6b24eacb95/