Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Compare TestNG with JUnit Jupiter for a new Java 25 project. Which features of TestNG have JUnit Jupiter caught up on, and which remain different?

JUnit Jupiter has caught up on most features that once favoured TestNG: parameterized tests, dynamic tests, tags, nested tests, an extension model, parallel execution and ordering. TestNG still differs in method and group dependencies, suite XML files, one instance per class by default, factories and its assertEquals(actual, expected) argument order. For a new Java 25 project JUnit Jupiter is the usual default, because Spring Boot, most libraries and IDEs centre on it, while TestNG remains a reasonable choice for existing suites.

Why this question is asked

Ten or fifteen years ago, choosing between TestNG and JUnit was a real decision with clear trade-offs: TestNG had groups, data providers, parallel runs and dependencies, and JUnit 4 had simplicity and popularity. Today the picture is different, and interviewers ask this question to check whether our knowledge is current or based on old blog posts. In this answer, we will recap where each framework came from, go through the features where JUnit Jupiter caught up, look at what still differs, including a detail that causes real bugs when people switch, and finish with a recommendation for a new project.

1A Quick Recap of Both Frameworks

TestNG was created in 2004 to fill gaps in JUnit 3, which had no annotations, no groups and no way to feed data into a test. It introduced annotations, configuration methods at several levels, groups, data providers, dependencies and parallel execution, all driven by an XML suite file. JUnit 4 adopted annotations soon after, and JUnit 5, released in 2017, was a complete redesign: the JUnit Platform for launching tests, Jupiter as the programming model, and an extension API. JUnit 6, released in 2025, continues the same Jupiter model with Java 17 as its baseline.

So when people today say JUnit, they usually mean JUnit Jupiter, the annotations in org.junit.jupiter.api, running on the JUnit Platform.

2Features JUnit Jupiter Has Caught Up On

Almost every feature that once pushed teams to TestNG now has a Jupiter equivalent. Data providers correspond to @ParameterizedTest with sources such as @CsvSource and @MethodSource. Groups correspond to @Tag, which Maven and Gradle can filter. Generated tests at runtime correspond to @TestFactory dynamic tests. Jupiter adds @Nested classes for grouping related tests, which TestNG has no direct equivalent for.

Java
// TestNG
@DataProvider(name = "amounts")
public Object[][] amounts() { return new Object[][] {{-5L}, {0L}}; }
@Test(dataProvider = "amounts", groups = "unit")
public void rejectsInvalid(long amount) {
assertThrows(IllegalArgumentException.class, () -> service.transfer(amount));
}
// JUnit Jupiter
@Tag("unit")
@ParameterizedTest
@ValueSource(longs = {-5, 0})
void rejectsInvalid(long amount) {
assertThrows(IllegalArgumentException.class, () -> service.transfer(amount)); // 2 results
}

Jupiter's extension model, @ExtendWith, replaced JUnit 4's runners and rules and is how Spring, Mockito and Testcontainers plug in. Parallel execution is available through configuration properties such as junit.jupiter.execution.parallel.enabled, and @TestMethodOrder with @Order gives an explicit order when we really need one.

3What Still Differs

Some differences remain, and they are deliberate design choices. TestNG has dependencies between tests, dependsOnMethods and dependsOnGroups, which Jupiter does not offer because it treats tests as independent. TestNG has suite XML files describing which classes, groups, parameters and parallel settings to run; Jupiter relies on the build tool and the Platform's suite support instead. TestNG has @Factory to create several instances of a test class with different constructor arguments.

The most important difference in daily work is the test instance lifecycle. TestNG creates one instance of a test class and runs all its methods on it, so fields carry over between tests. Jupiter creates a new instance for every test method by default, so each test starts with fresh fields; @TestInstance(Lifecycle.PER_CLASS) switches to the TestNG behaviour when needed.

TestNG and JUnit Jupiter today
FeatureTestNGJUnit Jupiter
Parameterized tests@DataProvider@ParameterizedTest with sources
Labels for selectiongroups@Tag
Tests generated at runtime@Factory, data providers@TestFactory dynamic tests
Parallel executiontestng.xml parallel modesConfiguration properties
Dependencies between testsdependsOnMethods, dependsOnGroupsNone, by design
Instance perClass (default)Method (default)
assertEquals order(actual, expected)(expected, actual)
Spring Boot test starterSupported, not the defaultDefault

4The Assertion Order Trap

The two assertEquals methods take their arguments in opposite order. TestNG's org.testng.Assert.assertEquals(actual, expected), and Jupiter's org.junit.jupiter.api.Assertions.assertEquals(expected, actual). Swapping them does not change whether the test passes, but it makes the failure message lie.

Java
int total = cart.total(); // 90, the bug: should be 100
// TestNG: assertEquals(actual, expected)
org.testng.Assert.assertEquals(total, 100);
// java.lang.AssertionError: expected [100] but found [90] <- correct message
// Same call order with JUnit Jupiter
org.junit.jupiter.api.Assertions.assertEquals(total, 100);
// org.opentest4j.AssertionFailedError: expected: <90> but was: <100> <- misleading

Notice that the second message tells the reader the code returned 100 and the test expected 90, the exact opposite of the truth. When migrating tests between the frameworks, this is the change that is easiest to get wrong, so automated migration tools rewrite the argument order, and many teams avoid the problem by using AssertJ, whose assertThat(actual).isEqualTo(expected) reads the same in both.

5Recommendation for a New Java 25 Project

For a new project, JUnit Jupiter is the usual default, and the reason is the ecosystem more than the features. spring-boot-starter-test brings Jupiter, Spring's test support is documented primarily for it, Testcontainers and Mockito ship Jupiter extensions, IDE templates generate Jupiter tests, and most developers joining the team already know it. Choosing TestNG means choosing the less common path for every integration.

TestNG remains a perfectly reasonable choice where it already is: a large existing suite, especially one that relies on dependencies, factories and suite files, works well and does not need rewriting. If a team wants both, the JUnit Platform can run TestNG tests through the TestNG engine, so new tests can use Jupiter while old ones keep running.

6Follow-up questions

Is there still a case for choosing TestNG for a new project?

A narrow one: a test-automation team building large end-to-end suites that genuinely rely on test dependencies, suite XML files and data provider features, and that already has TestNG expertise. Even then, the cost is swimming against the ecosystem, so the reason should be explicit.

Can JUnit Jupiter run tests in a fixed order?

Yes, with @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order on each method. That gives order but not dependency: a later test still runs if an earlier one failed. For journeys where a later step is meaningless after a failure, the usual Jupiter approach is to put the steps in one test or use assumptions.

What does TestNG's one instance per class mean for parallel runs?

With parallel = methods, all methods of a class run on the same object, so any field is shared across threads and can cause races. Jupiter's default per-method instances avoid that for instance fields, though static fields and shared resources are still shared in both frameworks.

7Conclusion

In this answer, we saw that TestNG was created to fill gaps in JUnit 3, and that JUnit Jupiter has since added parameterized and dynamic tests, tags, nested tests, extensions, parallel execution and ordering. TestNG still differs in dependencies, suite XML, factories, one instance per class and the assertEquals(actual, expected) order, which can make migrated failure messages misleading. For a new Java 25 project JUnit Jupiter is the usual default because the ecosystem centres on it, and TestNG remains fine for existing suites.

What to say in the interviewAbout 90 seconds aloud

Open with

Most of the features that once made people choose TestNG now exist in JUnit Jupiter. Data providers became @ParameterizedTest with sources like ValueSource or MethodSource, groups became @Tag, there are dynamic tests with @TestFactory, nested test classes, a proper extension model that Spring, Mockito and Testcontainers use, parallel execution through configuration properties, and explicit ordering with @TestMethodOrder.

Then, if they want more

What still differs is mostly by design. TestNG has dependencies between tests with dependsOnMethods and dependsOnGroups, which Jupiter deliberately does not offer. TestNG has suite XML files and @Factory. And TestNG creates one instance of the test class for all its methods, while Jupiter creates a new instance per method by default, which matters for fields and for parallel runs.

There is also a small but real trap: TestNG's assertEquals takes actual then expected, Jupiter takes expected then actual, so a mechanical migration that keeps the order produces failure messages that say the opposite of the truth.

For a new Java 25 project I would pick JUnit Jupiter, mainly because of the ecosystem: Spring Boot's test starter brings it, the Spring docs and most libraries focus on it, and new developers know it.

For an existing TestNG suite that works, I would not rewrite it just for that; it can even run on the JUnit Platform through the TestNG engine alongside new Jupiter tests.

About this answer

Last updated
12 November 2026
Versions it names
JUnit 4, JUnit 3, Java 25, JUnit 5
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.
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 "Compare TestNG with JUnit Jupiter for a new Java 25 project. Which features of TestNG...": https://scrivio-interview-library.netlify.app/java/testng/8722ed90df/