Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

What is the JUnit Platform Launcher, and how do IDEs and build tools use it? Explain TestEngine, the Launcher API and TestExecutionListener.

The JUnit Platform splits testing into two halves: the Launcher, which IDEs and build tools call to discover and run tests, and TestEngines, such as Jupiter, Vintage, Spock or Cucumber, which know how a particular kind of test is written. A tool builds a LauncherDiscoveryRequest with selectors and filters and calls Launcher.execute(); each engine turns its tests into a tree of TestDescriptors and runs them, and TestExecutionListeners receive events such as executionStarted and executionFinished, which is how reports and IDE trees are built.

Why this question is asked

Most of us use JUnit 5 through an IDE button or mvn test and never see the layer underneath. That layer is what made JUnit 5 different from JUnit 4: one platform that many testing frameworks plug into, and one API that every tool talks to. Interviewers ask about it because understanding it explains a lot of everyday behaviour, why Spock and Jupiter tests run in the same build, why the IDE shows a tree, how reports are written, and where to hook in for custom reporting. In this answer, we will look at the three parts of JUnit 5, follow a run from the IDE through the Launcher to the engines, look at the TestEngine contract, and see how TestExecutionListener turns the run into reports.

1A Quick Recap of the Three Parts of JUnit 5

JUnit 5 is not one library. It is three. The JUnit Platform is the foundation: it defines how tests are discovered and executed and offers the Launcher API to tools. JUnit Jupiter is the programming model we write tests in, @Test, @BeforeEach, extensions, plus the engine that runs those tests. JUnit Vintage is an engine that runs old JUnit 3 and 4 tests on the same platform.

The important idea is the split. The platform does not know what a Jupiter test looks like, and Jupiter does not know whether it is running in IntelliJ, Maven or Gradle. They meet through two interfaces: TestEngine, which engines implement, and Launcher, which tools call. Any framework can provide an engine, which is why Spock, Cucumber, Kotest and jqwik all run on the same platform.

Step throughWho talks to whom
  1. ToolsIntelliJ, Eclipse, Maven Surefire, Gradle, the console launcher
  2. Launcher APILauncherDiscoveryRequest, Launcher.execute, listeners
  3. JUnit Platform engine APITestEngine, TestDescriptor, ExecutionRequest
  4. Test enginesjunit-jupiter, junit-vintage, spock, cucumber, suite
  5. Our testsclasses, methods, feature files

5 layers, from the top down. Step through them one at a time.

2How a Tool Starts a Run

When we click 'run' on a package in the IDE, or run mvn test, the tool does the same three things. It creates a Launcher. It builds a LauncherDiscoveryRequest that describes what to run: selectors say where to look, such as a package, a class, a method or a classpath resource, and filters narrow the result, such as tags or class name patterns. Then it calls execute() with one or more listeners that receive the results.

Java
Launcher launcher = LauncherFactory.create();
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(DiscoverySelectors.selectPackage("com.acme.billing"))
.filters(TagFilter.excludeTags("integration"),
ClassNameFilter.includeClassNamePatterns(".*Test"))
.build();
SummaryGeneratingListener summary = new SummaryGeneratingListener();
launcher.execute(request, summary);
summary.getSummary().printTo(new PrintWriter(System.out));
// 42 tests found, 42 tests successful, 0 tests failed ...

Notice that this is ordinary Java. Surefire and Gradle contain code very much like this, which is why the tag expressions and selectors we use in build files behave the same everywhere: the tools only translate their configuration into a discovery request.

3What a TestEngine Does

The Launcher finds engines with Java's ServiceLoader: each engine jar contains a file META-INF/services/org.junit.platform.engine.TestEngine naming its implementation class. An engine has a unique id, such as junit-jupiter, and two main jobs.

In discover(), the engine receives the discovery request and returns a tree of TestDescriptor objects, one node per container or test. For Jupiter, the engine is the root, each test class is a container, each @Test method is a test, and a @ParameterizedTest method is a container whose children are created as it runs. Each node has a unique id, such as [engine:junit-jupiter]/[class:com.acme.InvoiceTest]/[method:addsTax()], and a display name. In execute(), the engine walks its tree, runs each node and reports what happens to an EngineExecutionListener, which the platform passes on to the tool's listeners.

Step throughOne run from the IDE
IDELauncherJupiter engineListener
execute(request, listener)
discover(request)
TestDescriptor tree
testPlanExecutionStarted(plan)
execute(tree)
executionStarted(addsTax)
executionFinished(addsTax, SUCCESSFUL)
testPlanExecutionFinished(plan)

8 messages in order. Play them, or step through them one at a time.

The IDE builds its tree of green and red ticks from these listener events.

4TestExecutionListener: How Results Become Reports

TestExecutionListener is the interface tools implement to see what happens during a run. All its methods have empty default implementations, so a listener only overrides what it needs. The main ones are testPlanExecutionStarted and testPlanExecutionFinished around the whole run, executionStarted and executionFinished around each test or container (with a TestExecutionResult of SUCCESSFUL, FAILED or ABORTED), executionSkipped with a reason for disabled tests, dynamicTestRegistered for tests created while running, and reportingEntryPublished for extra key-value data that a test publishes through TestReporter.

Java
public class FailurePrinter implements TestExecutionListener {
@Override
public void executionFinished(TestIdentifier id, TestExecutionResult result) {
if (id.isTest() && result.getStatus() == TestExecutionResult.Status.FAILED) {
System.out.println("FAILED " + id.getDisplayName() + ": "
+ result.getThrowable().map(Throwable::getMessage).orElse(""));
}
}
}
// FAILED addsTax(): expected: <107> but was: <105>

Surefire's XML writer, Gradle's report, the IDE tree and JUnit's own Open Test Reporting output are all built on these events. We can add our own listener to every run, without touching any test, by registering it with ServiceLoader: a file META-INF/services/org.junit.platform.launcher.TestExecutionListener on the test classpath, containing the listener's class name. The Launcher loads every listener named there automatically.

5Follow-up questions

What is the difference between TestEngine and a Jupiter extension?

An extension plugs into the Jupiter engine and changes how Jupiter tests run, for example by injecting parameters or wrapping tests in transactions, as Spring's SpringExtension does. An engine is a whole test framework at the platform level, with its own way of finding and running tests. Spock is an engine; Mockito's MockitoExtension is an extension.

How can I run tests from a plain main method or a script?

With the Launcher API as shown above, or with the JUnit console launcher, a standalone jar that wraps the Launcher and accepts selectors and tag filters on the command line. It is useful in environments without Maven or Gradle.

What is LauncherSessionListener?

It is a listener for the whole launcher session, which can span several discovery and execution calls in one JVM, for example in an IDE or a Gradle worker. It is a good place to start and stop expensive shared resources once per session rather than once per test plan.

6Conclusion

In this answer, we saw that the JUnit Platform separates the tools that start tests from the engines that understand them. Tools build a LauncherDiscoveryRequest with selectors and filters and call Launcher.execute(); engines such as Jupiter, Vintage, Spock and Cucumber, found through ServiceLoader, discover their tests into a TestDescriptor tree and execute it; and TestExecutionListeners receive events such as executionStarted, executionFinished and reportingEntryPublished, from which every report and IDE tree is built. Listeners can be registered for all runs through a META-INF/services file.

What to say in the interviewAbout 80 seconds aloud

Open with

JUnit 5 is really three parts: the Platform, Jupiter and Vintage. The Platform is the layer that discovers and runs tests, and it separates two roles. Test engines know how a kind of test is written: Jupiter for JUnit 5 tests, Vintage for JUnit 4, and third-party ones like Spock or Cucumber.

Then, if they want more

Engines are found through ServiceLoader. The Launcher is the API that IDEs and build tools call. When I run tests in IntelliJ or with mvn test, the tool builds a LauncherDiscoveryRequest with selectors, like a package or a class, and filters, like tag expressions or class name patterns, and calls Launcher.execute with some listeners.

The Launcher asks every engine to discover its tests, and each engine returns a tree of TestDescriptors, the engine at the root, then classes as containers and methods as tests, each with a unique id. Then each engine executes its tree and reports events.

Those events reach TestExecutionListener implementations: executionStarted, executionFinished with a result of successful, failed or aborted, executionSkipped, reportingEntryPublished and the test plan start and finish. Surefire's XML reports and the IDE's tree are both built from those events. And if I want my own listener on every run without touching tests, I register it in META-INF/services/org.junit.platform.launcher.TestExecutionListener.

About this answer

Last updated
12 November 2026
Versions it names
JUnit 5, JUnit 3, JUnit 4
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
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 "What is the JUnit Platform Launcher, and how do IDEs and build tools use it? Explain...": https://scrivio-interview-library.netlify.app/java/junit/c039682e1e/