Quick revision
The short answer
I would start by mapping the configuration hierarchy, because a failure in a shared @BeforeClass or @BeforeMethod deep in a base class skips every test that depends on it and hides the real cause behind hundreds of SKIPPED results. Then I would replace inheritance with composition, meaning helper objects, fixtures and listeners that each test class uses explicitly, make configuration methods idempotent and fast, and move expensive setup such as databases and containers into suite-level fixtures with clear owners. In CI, skips become a first-class metric and a skip caused by a configuration failure fails the build. If the organisation is moving to JUnit, I would migrate in slices with both engines in the build during the transition.
What to remember
In this answer, we tackled a legacy TestNG suite where failures cascade into hundreds of skips. We mapped the configuration hierarchy and measured which setup caused the skips, replaced inheritance with explicit composition, made configuration idempotent and fast with expensive setup in owned suite-level fixtures, treated configuration-caused skips as build failures, and planned a slice-by-slice migration with both engines in the build if moving to JUnit.
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.
I would start by mapping the configuration hierarchy, because a failure in a shared @BeforeClass or @BeforeMethod deep in a base class skips every test that depends on it and hides the real cause behind hundreds of SKIPPED results. Then I would replace inheritance with composition, meaning helper objects, fixtures and listeners that each test class uses explicitly, make configuration methods idempotent and fast, and move expensive setup such as databases and containers into suite-level fixtures with clear owners. In CI, skips become a first-class metric and a skip caused by a configuration failure fails the build. If the organisation is moving to JUnit, I would migrate in slices with both engines in the build during the transition.
Why this question is asked
Large TestNG suites in enterprises often grew around a chain of base classes: BaseTest, then BaseApiTest, then BaseOrderApiTest, each adding setup. It works until one setup step fails, and then the report shows 600 skipped tests and one configuration failure buried in the log. Interviewers ask this scenario to see whether we understand why the cascade happens and can lead a gradual repair of a suite many teams depend on. In this answer, we will see why failures cascade, how to map the hierarchy, how to replace inheritance with composition, how to make setup robust, how to make skips visible, and how to migrate if we are moving to JUnit.
1Why Failures Cascade Into SKIPPED
In TestNG, when a configuration method such as @BeforeClass or @BeforeMethod throws, the tests that depend on it are reported as SKIPPED, not FAILED, on the reasoning that they never got a chance to run. With the default configfailurepolicy of skip, later configuration methods are skipped as well.
In a deep hierarchy, every test class inherits the base classes' configuration methods. If BaseTest's @BeforeMethod logs in to a shared test server, and that server is slow one morning, the login fails before every test of every class. A run of 900 tests then shows a handful of configuration failures and hundreds of skips. The summary may even show zero failures. Engineers learn to rerun the build, and real problems are hidden in the noise.
- BaseTest
@BeforeSuiteload config;@BeforeMethodlog in to test server - BaseApiTest
@BeforeClasscreate REST client;@BeforeMethodreset test data - BaseOrderApiTest
@BeforeClassseed products in shared database - OrderCancelTestthe 12 tests a reader actually cares about
4 layers, from the top down. Step through them one at a time.
A failure in any layer above skips every test below it, and the cause is far from the tests.
2Mapping the Hierarchy First
Before changing anything, we need to know what runs where. I would write a short script, or use a listener, to list every configuration method with its class, level and which test classes inherit it. In a suite like this, it is common to find that a test class inherits ten or more configuration methods, some of which it does not need: database seeding in a test that never touches the database, a browser start in an API test.
The same listener can record, for each run, which configuration method failed and how many tests it skipped. After a week of CI data we usually find that two or three setup methods cause most of the skips. Those are where to start, because fixing them removes most of the noise.
3Replacing Inheritance With Composition
The structural fix is to stop inheriting setup. Instead of extending a base class that does everything, each test class creates or receives the helpers it needs, and the helpers are named for what they do: an ApiClient fixture, a TestDataSeeder, a SessionFixture. The test class's own setup then reads as a short, explicit list.
Notice two changes besides the explicitness. The test no longer resets shared data before every method; it creates its own order, which removes a source of both failures and interference between tests. And a failure now names something specific in this class, such as createPaidOrder failing, instead of an anonymous setup method three classes up.
4Making Setup Idempotent, Fast and Owned
Configuration methods should be idempotent, meaning safe to run twice with the same result, and fast. Creating a unique order per test is idempotent; deleting all orders and reinserting seed data is neither fast nor safe when classes run in parallel. A slow @BeforeMethod is especially costly: 300 milliseconds before each of 3,000 tests is 15 minutes per run.
Expensive setup such as databases, message brokers and containers belongs at suite level, started once. A small set of suite fixtures, for example one PostgreSQL container with Testcontainers and one WireMock server, is started by an ISuiteListener or a @BeforeSuite method in a dedicated class, and each fixture has a named owning team. When a fixture fails, the run stops with one clear error instead of producing hundreds of skips, which is better for everyone.
5Making Skips Visible, and Migrating in Slices
In CI, I would report skipped tests as a first-class number next to passed and failed, with a trend per team. The rule is simple: a skip caused by a configuration failure fails the build. Deliberate skips, such as a test disabled for a known issue with a ticket, are allowed but listed. With that rule, nobody can treat a green summary with 400 skips as a passing run.
If the organisation is also moving to JUnit Jupiter, the same work prepares for it, because composed fixtures translate directly into Jupiter extensions and plain helper objects, while deep TestNG base classes do not. I would migrate one module or team at a time. The JUnit Platform can run TestNG tests through the TestNG engine for the platform, so both kinds of tests run in one build and one report during the transition. Automated refactoring tools such as OpenRewrite can handle much of the mechanical change, such as annotations and assertion argument order; check which recipes exist for your versions. Each migrated module drops its TestNG dependency, and the last base class is deleted when nothing extends it.
- Map configuration methods and inheritance
- Record which setup causes most skips
- Fix the top offenders, compose instead of inherit
- Move expensive setup to suite fixtures with owners
- Fail CI on configuration-caused skips
- Migrating to JUnit?YesMove module by module, both engines in the buildNoKeep improving TestNG classes
6 steps in order. Play them, or step through them one at a time.
Each step reduces noise before the next one starts.
6Follow-up questions
Should we set configfailurepolicy to continue to reduce skips?
It can reduce the cascade, because later configuration methods still run after one fails, but it treats the symptom. Tests may then run against half-prepared state and fail in confusing ways. I would use it only as a short-term aid while fixing the failing setup, not as the solution.
How do you persuade teams to give up their base classes?
Show them the data: the skip counts their base class causes and the time its setup adds to every run. Then provide ready-made fixtures that are easier to use than the base class, and convert one team's classes together as an example. Once the first module shows fewer skips and faster runs, others follow.
What about tests that rely on dependsOnMethods across a scenario?
Those dependencies also produce skips by design, which is fine for a true multi-step scenario. But many suites use them to share state between tests that should be independent. I would keep dependsOnMethods only for genuine scenarios and give every other test its own data.
7Conclusion
In this answer, we tackled a legacy TestNG suite where failures cascade into hundreds of skips. We mapped the configuration hierarchy and measured which setup caused the skips, replaced inheritance with explicit composition, made configuration idempotent and fast with expensive setup in owned suite-level fixtures, treated configuration-caused skips as build failures, and planned a slice-by-slice migration with both engines in the build if moving to JUnit.
Open with
The skips are a symptom of the hierarchy. In TestNG, when a @BeforeClass or @BeforeMethod throws, every dependent test is reported as skipped, and with deep base classes every test inherits setup it may not even need.
Then, if they want more
So one slow login in a base class skips hundreds of tests and the real cause is buried. First I would map it: list every configuration method, which classes inherit it, and add an IConfigurationListener that records which setup failed and how many tests it skipped. Usually two or three methods cause most of the noise, so those come first.
The structural change is composition instead of inheritance: each test class creates the helpers it needs, like an API client fixture or a test data helper, so its setup is explicit and a failure names something specific.
I would make configuration idempotent and fast, for example each test creates its own order instead of resetting shared data before every method, and move expensive things like databases and containers into suite-level fixtures, started once and owned by a named team. In CI, skips become a visible number and any skip caused by a configuration failure fails the build.
If we are moving to JUnit, I would migrate module by module, running TestNG tests on the JUnit Platform through the TestNG engine so both live in one build, and use automated refactoring for the mechanical parts.
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 "Your organisation has a large legacy TestNG suite with deep base class hierarchies of...": https://scrivio-interview-library.netlify.app/java/testng/51dcca1874/