Jump to ratings and reviews
Rate this book

JUnit in Action, Third Edition

Rate this book
JUnit in Action, Third Edition has been completely rewritten for this release. The book is full of examples that demonstrate JUnit's modern features, including its new architecture; nested, tagged, and dynamic tests; and dependency injection.

Summary
JUnit is the gold standard for unit testing Java applications. Filled with powerful new features designed to automate software testing, JUnit 5 boosts your productivity and helps avoid debugging nightmares. Whether you're just starting with JUnit or you want to ramp up on the new features, JUnit in Action, Third Edition has you covered. Extensively revised with new code and new chapters, JUnit in Action, Third Edition is an up-to-date guide to smooth software testing. Dozens of hands-on examples illustrate JUnit 5's innovations for dependency injection, nested testing, parameterized tests, and more. Throughout, you’ll learn how to use JUnit 5 to automate your testing, for a process that consumes less resources, and gives you more time for developing.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology
The JUnit framework is the gold standard for unit testing Java applications—and knowing it is an essential skill for Java developers. The latest version, JUnit 5, is a total overhaul, now supporting modern Java features like Lambdas and Streams.

About the book
JUnit in Action, Third Edition has been completely rewritten for this release. The book is full of examples that demonstrate JUnit's modern features, including its new architecture; nested, tagged, and dynamic tests; and dependency injection. You'll benefit from author Catalin Tudose's unique "pyramid" testing strategy, which breaks the testing process into layers and sets you on the path to bug-free code creation.

What's inside

Migrating from JUnit 4 to 5
Effective test automation
Test-driven development and behavior-driven development
Using mocks for test isolation
Connecting JUnit 5 with Maven or Gradle

About the reader
For intermediate Java developers.

About the author
Catalin Tudose has a Ph.D. in Computer Science, and over 15 years of experience as a Senior Java Developer and Technical Team Lead. Previous editions were authored by Petar Tahchiev, Felipe Leme, Gary Gregory, and Vincent Massol.

Table of Contents

PART 1 - JUNIT

1 JUnit jump-start

2 Exploring core JUnit

3 JUnit architecture

4 Migrating from JUnit 4 to JUnit 5

5 Software testing principles

PART 2 - DIFFERENT TESTING STRATEGIES

6 Test quality

7 Coarse-grained testing with stubs

8 Testing with mock objects

9 In-container testing

PART 3 - WORKING WITH JUNIT 5 AND OTHER TOOLS

10 Runing JUnit tests from Maven 3

11 Running JUnit tests from Gradle 6

12 JUnit 5 IDE support

13 Coninuous integration with JUnit 5

PART 4 - WORKING WITH MODERN FRAMEWORKS AND JUNIT 5

14 JUnit 5 extension model

15 Presentation-layer testing

16 Testing Spring applications

17 Testing Spring Boot applications

18 Testing a REST API

19 Testing database applications

PART 5 - DEVELOPING APPLICATIONS WITH JUNIT 5

20 Test-driven development with JUnit 5

21 Behavior-driven development in JUnit 5

22 Implementing a test pyramid strategy with JUnit 5

525 pages, Paperback

Published December 8, 2020

4 people are currently reading
44 people want to read

About the author

Catalin Tudose

2 books2 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
2 (6%)
4 stars
16 (51%)
3 stars
6 (19%)
2 stars
7 (22%)
1 star
0 (0%)
Displaying 1 - 2 of 2 reviews
Profile Image for Cristian.
41 reviews
December 26, 2024
This book could have been so much more, but it’s hard to recommend unfortunately. It follows a common pattern I’ve noticed lately in software books where things are explained and re-explained, leading to a lot of bloat. All code snippets have sections marked with numbers, which are then clarified. This might be useful for someone without experience, or when something new is introduced in the text. However, when done for every piece of code (which many times repeats something shown before) it becomes extremely tedious. In the end, there is lots of redundancy, and it gets particularly boring during the Cucumber vs JBehave framework comparison.

Some wording is unfortunate, particularly how the author talks about tests “proving” that the code works, or that “a passing unit test suite confirms that your code works”. Given the author’s background, I’m sure he knows this is not exactly true. Tests will at best show that the specific scenarios you are testing work (assuming the test is correctly written!), which is far from proving, unless you are testing every possible permutation of inputs and states, which is usually impossible (prohibitively expensive).


The book (from 2020) recommends in chapter 10 using the maven-eclipse-plugin, which has been retired (no longer maintained) since at least 2015. It also spends some time with the Arquillian testing framework, which has no JUnit 5 integration (only JUnit 4), nor does it seem to be properly maintained anymore.

Examples could also be improved. For instance, there are no (when there should be) uses of try-with-resources in the JDBC examples of Chapter 19. There are also many useless assertions, e.g. using assertNotNull on the result of getResultList() of a JPA Query (it’s never null, if nothing is retrieved, it’s an empty list). You might miss this if you aren’t familiar with the API, but even worse is checking that the result of a constructor is not null, such as when in the book we find:

Passenger passenger = new Passenger("900-45-6789", "John Smith", "GB");
assertNotNull(passenger);

Lastly, more of a nitpick or personal preference, but I think there are also unnecessary uses of @BeforeEach in the examples, such as:

private Flight economyFlight;
@BeforeEach void setUp() {
economyFlight = new EconomyFlight("1");
}

In such a case it’s simpler to define the field inline:



private Flight economyFlight = new EconomyFlight("1");

Doing so is shorter and allows the field to be final, making the code easier to understand.

It's possible the author just wanted to demonstrate the usage of @BeforeEach, but one has to keep in mind that the book and author are effectively an authority for any newcomer wanting to learn from it, and they will unfortunately end up repeating such snippets.

I was also hoping to find information about the JUnit 5 ExtensionContext.Store and Namespaces, but there is none.

For those new to testing in Java, the book covers a good breadth of topics and might be worthwhile, but will require having to fight through all the redundancy in it, which is a shame, as it could have been a lot shorter and contain more up to date and useful information.
2 reviews
August 12, 2025
These are two citations from two different paragraphs on the same page (page 50):

Citation 1: "Reflection breaks encapsulation, of course, but this technique was the only way to provide extensibility in JUnit 4 and earlier versions."

Citation 2: "We can extend the JUnit 4 abstract Runner class, overriding its methods and working with reflection. This approach breaks encapsulation but was the only way to add custom functionality to JUnit 4."

I stopped reading the book after this. I really dislike it when the same ideas are repeated multiple times—especially on the same page, using almost the exact same words. I just can’t.
Displaying 1 - 2 of 2 reviews

Can't find what you're looking for?

Get help and learn more about the design.