Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2025 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

1. Overview

The Engine Test Kit allows us to execute Test Plans and gather statistics and reports at varying levels of detail depending on our needs. For example, it provides us with an overview of how many tests pass and fail. Or, we can check if the individual test outcomes match what we expected.

In this tutorial, we’ll look at what JUnit 5s Engine Test Kit is and how we can use it in our applications.

2. Example Test Class

To start, we’ll need a test class that we want to run and gather information on. To make the information we gather interesting, we need tests that pass, fail, skip, and abort.

Let’s first define a small Object to use in our tests, a Display that has a Platform and a height:

public class Display {
    private final Platform platform;
    private final int height;
    // standard constructor, getters and setters
}

Let’s then write the Platform enum:

public enum Platform {
    DESKTOP,
    MOBILE
}

We’ll use the Platform we’ve just defined to allow us to have tests that should only run for mobile displays. Now we’ve got our test Objects, let’s use them in a test class:

public class DisplayTest {
    private final Display display = new Display(Platform.DESKTOP, 1000);

    @Test
    void whenCorrect_thenSucceeds() {
        assertEquals(1000, display.getHeight());
    }

    @Test
    void whenIncorrect_thenFails() {
        assertEquals(500, display.getHeight());
    }

    @Test
    @Disabled("Flakey test needs investigating")
    void whenDisabled_thenSkips() {
        assertEquals(999, display.getHeight());
    }

    @Test
    void whenAssumptionsFail_thenAborts() {
        assumeTrue(display.getPlatform() == Platform.MOBILE, "test only runs for mobile");
    }
}

Here we’ve got a suite of four tests. The first will succeed as we’ve got the correct height. The second will fail as we’ve got the height wrong. The third will be skipped as it’s marked with the @Disabled annotation. Finally, the fourth will abort as it should only run for mobile Displays, and the Display under test is for desktops.

3. Verify the Test Engine

The Engine Test Kit gives us the ability to use the Test Engine we decide on. The default one in Junit 5 is junit-jupiter. However, it’s possible to write our own or to use others, such as junit-vintage, which is handy for running older versions of JUnit.

A good way to start off our tests is to confirm we can find the Test Engine we would like to use. We can then also check that the Test Engine picks up our Test Plan. Let’s write a test that does both of those tasks:

@Test
void givenJunitJupiterEngine_whenRunningTestSuite_thenTestsAreDiscovered() {
    EngineDiscoveryResults results = EngineTestKit.engine("junit-jupiter")
        .selectors(selectClass(DisplayTest.class))
        .discover();
    assertEquals(emptyList(), results.getDiscoveryIssues());
}

In this test, we’ve started by specifying the name of the Test Engine we want to use, “junit-jupiter“. Then we’ve passed in our test class, and finally called discover(). Our assertion on the final line confirms that there were no issues with the discovery. Reviewing any issues that do pop up here is a good way to debug anything that’s gone wrong.

4. Collecting High-Level Test Statistics

So now we’ve got a Test Plan, and we’ve verified that our selected Test Engine is available and will detect our tests. It’s time to run our tests and gather up some high-level statistics:

@Test
void givenTestSuite_whenRunningAllTests_thenCollectHighLevelStats() {
    EngineTestKit
        .engine("junit-jupiter")
        .selectors(selectClass(DisplayTest.class))
        .execute()
        .testEvents()
        .assertStatistics(stats ->
            stats.started(3).finished(3).succeeded(1).failed(1).skipped(1).aborted(1));
}

This test starts similarly to the last one; we specify our Test Engine and our test class. Following on from that setup, we call execute() to run the tests. After the run, we assert all our expected statistics. Here we can see that we got a single instance of a success, failure, skip, and abort as expected.

There are other statistics we could have checked. For example, dynamicallyRegistered() would check the number of dynamic registration events that occurred during the Test Plan.

5. Collecting Test-Specific Events

Next, let’s look at how we can drill down even further into the results of our Test Plan.

5.1. Verifying the Reason for an Aborted Test

We know that we’re expecting one of our tests to be aborted. Before, we were able to assert that at least one test was aborted. However, it’s essential to understand that the test is aborting correctly, and that it’s doing so for the expected reason. We can use the Engine Test Kit to make sure of that by collecting the Events from the test run:

Events testEvents = EngineTestKit
    .engine("junit-jupiter")
    .selectors(selectMethod(DisplayTest.class, "aborts"))
    .execute()
    .testEvents();

In the code here, we’ve specified our Test Engine like usual. We’ve then selected the specific method aborts() from our DisplayTest class that we want to be looking at. To wrap up, we then run the test and ask for the Events to be returned. With our Events collected, we can now check that the abort happened and that the reason is what we expected:

testEvents.assertThatEvents()
    .haveExactly(1, event(test("aborts"),
        abortedWithReason(instanceOf(TestAbortedException.class),
            message(message -> message.contains("test only runs for mobile")))));

In this section of the test, we are asserting three things. Firstly, we check that there’s only one event, as we only expected to run one test; this effectively verifies that we set things up right. We then use abortedWithReason() to check that we did actually abort the test and that the message is what we expected; the test only runs for mobile displays.

5.2. Verifying Reason For Failed Test

Let’s look at verifying a test failed as expected, and for the reason we expected. To start as before, we’ll select a test engine, our fails() test, and collect the Events:

Events testEvents = EngineTestKit
    .engine("junit-jupiter")
    .selectors(selectMethod(DisplayTest.class, "fails"))
    .execute()
    .testEvents();

This time, we’ll check for two things: firstly, that we have a single Event for the single test. Secondly, we’ll use the finishedWithFailure() method to check that the test did fail as expected and the error that caused the failure is the right one:

testEvents.assertThatEvents()
    .haveExactly(1, event(test("fails"),
        finishedWithFailure(instanceOf(AssertionFailedError.class))));

We can be confident that the right test failed for the right reason using these assertions. Of course, we could be checking for any Error or Exception type here.

Alongside the abortedWithReason() and finishedWithFailure() methods we’ve used here, there’s a whole suite of methods for asserting that tests run or don’t run as expected. For example skippedWithReason(), finishedSuccessfully() and finishedWithCause().

6. Conclusion

In this tutorial, we saw how the Engine Test Kit allows us to run a suite of tests. We tracked high-level statistics, such as the number of tests run, and measured the number of tests that passed, failed, skipped, and aborted. However, we could have tracked a range of other test outcomes.

We then went deeper and wrote tests to assert why a test was aborted or failed. This was helpful for knowing things aren’t changing and new failure reasons aren’t coming up.

As always, the full code for the examples is available over on GitHub.

Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2025 – NPI (All)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments