TestNG: groups, parameters and data providers
Run the same Java test with many inputs, pick which tests run, and share setup. Learn the TestNG features that go past a single JUnit-style test.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a playlist. A playlist lets you play a few songs for a short drive and all of them for a long one. You do not change the songs, only the list.
A song can sit on more than one playlist.
A group is a playlist of tests. Tom, the tester at Daily List, a to-do list app, plays the smoke list before every push. The aim is to change what runs without changing the tests themselves.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A playlist you choose for a short drive or a long one.
- Group
- Pick
- Run
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The playlist | A test group |
| The songs | The tests |
| Playing one song many ways | A data provider |
| The settings page | A suite file |
WHERE THIS PICTURE STOPS
- A playlist plays in order, but a group does not set order.
- A song is the same each time, but a row changes the input.
- A playlist is yours, but a suite file is shared.
HOOK
Choose the list, play it.
TELL A FRIEND
A playlist: pick the list, not the songs.
OFTEN MIXED UP WITH Test runners: JUnit, TestNG and pytest. That topic compares three runners. This one goes deep on TestNG groups and data providers.
PRACTISE AND KEEP
Sources for this topic — 2 sources
- Market practice
Annotations (TestNG documentation) ↗ — TestNG · TestNG documentation: groups are set on a test and the run can include or exclude groups by name, and setup and cleanup methods can run before or after a group (search excerpt, page not opened)
Primary publisher body opened and relevant sections read on 6 November 2026; selected-section reading, not a claim every page or external link was read. See docs/research/v16-testing-automation-literacy-audit-20261106.md for exact sections, version and limitations.
- Market practice
Parameters (TestNG documentation) ↗ — TestNG · TestNG documentation: a data provider is a method that returns rows of values and a test names it, so the test runs once for each row (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.