Welcome to Manning India!

We are pleased to be able to offer regional eBook pricing for Indian residents.
All eBook prices are discounted 40% or more!
JUnit in Action, Third Edition
Cătălin Tudose, Petar Tahchiev, Felipe Leme, Vincent Massol, and Gary Gregory
  • MEAP began November 2019
  • Publication in Summer 2020 (estimated)
  • ISBN 9781617297045
  • 525 pages (estimated)
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

This is the go-to reference for JUnit 5, for both beginners and experts alike.

Kent R. Spillner
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.
Table of Contents detailed table of contents

Part 1: JUnit 5 essentials

1 JUnit jump-start

1.1 Proving it works

1.2 Starting from scratch

1.3 Understanding unit-testing frameworks

1.4 JUnit design goals

1.5 Setting up JUnit

1.6 Testing with JUnit

1.7 Summary

2 Exploring Core JUnit

2.1 Core annotations

2.1.1 The @DisplayName annotation

2.1.2 The @Disabled annotation

2.2 Nested tests

2.3 Tagged tests

2.4 Assertions

2.5 Assumptions

2.6 Dependency injection in JUnit 5

2.7 Repeated tests

2.8 Parameterized tests

2.9 Dynamic tests

2.10 Using Hamcrest matchers

2.11 Summary

3 JUnit architecture

3.1 The concept and importance of software architecture

3.2 JUnit 4 architecture

3.2.1 JUnit 4 modularity

3.2.2 JUnit 4 runners

3.2.3 JUnit 4 rules

3.2.4 Shortcomings of the JUnit 4 architecture

3.3 JUnit 5 architecture

3.3.1 JUnit 5 modularity

3.3.2 JUnit 5 Platform

3.3.3 JUnit 5 Jupiter

3.3.4 JUnit 5 Vintage

3.3.5 The big picture of the JUnit 5 architecture

3.4 Summary

4 Migrating from JUnit 4 to JUnit 5

4.1 The steps between JUnit 4 and JUnit 5

4.2 Needed dependencies

4.3 Annotations, classes and methods

4.4 Rules vs the extension model

4.5 Summary

5 Software Testing Principles

5.1 The need for unit tests

5.1.1 Allowing greater test-coverage

5.1.2 Increasing team productivity

5.1.3 Detecting regressions and limiting debugging

5.1.4 Refactoring with confidence

5.1.5 Improving implementation

5.1.6 Documenting expected behavior

5.1.7 Enabling code coverage and other metrics

5.2 Test types

5.2.1 The types of software tests

5.3 Black box vs. white box testing

5.4 Summary

Part 2: Different testing strategies

6 Tests quality

6.1 Measuring test coverage

6.1.1 Introduction to test coverage

6.1.2 Code coverage measuring tools

6.2 Writing testable code

6.2.1 Public APIs are contracts

6.2.2 Reduce dependencies

6.2.3 Create simple constructors

6.2.4 Follow “The Principle of Least Knowledge”

6.2.5 Avoid hidden dependencies and global state

6.2.6 Favor generic methods

6.2.7 Favor composition over inheritance

6.2.8 Favor polymorphism over conditionals

6.3 Test-Driven Development

6.3.1 Adapting the development cycle

6.3.2 The TDD two-step

6.4 Behavior-Driven Development

6.5 Mutation Testing

6.6 Testing in the development cycle

6.7 Summary

7 Coarse-grained testing with stubs

7.1 Introducing stubs

7.2 Stubbing an HTTP connection

7.2.1 Choosing a stubbing solution

7.2.2 Using Jetty as an embedded server

7.3 Stubbing the web server resources

7.3.1 Setting up the first stub test

7.3.2 Reviewing the first stub test

7.4 Stubbing the connection

7.4.1 Producing a custom URL protocol handler

7.4.2 Creating a JDK HttpURLConnection stub

7.4.3 Running the test

7.5 Summary

8 Testing with mock objects

8.1 Introducing mock objects

8.2 Unit testing with mock objects

8.3 Refactoring with Mock objects

8.3.1 Refactoring example

8.4 Mocking an HTTP connection

8.4.1 Defining the mock objects

8.4.2 Testing a sample method

8.4.3 Try #1: easy method refactoring technique

8.4.4 Try #2: refactoring by using a class factory

8.5 Using mocks as Trojan horses

8.6 Introducing Mock frameworks

8.6.1 Using EasyMock.

8.6.2 Using JMock

8.6.3 Using Mockito

8.7 Summary

9 In-container testing

9.1 Limitations of standard unit testing

9.2 The Mock objects solution

9.3 The step to in-container testing

9.3.1 Implementation strategies

9.3.2 In-container testing frameworks

9.4 Comparing stubs, mock objects, and in-container testing

9.4.1 Stubs evaluation

9.4.2 Mock objects evaluation

9.4.3 In-container testing evaluation

9.5 Testing with Arquillian

9.6 Summary

Part 3: Working with JUnit 5 and other tools

10 Running JUnit tests from Maven 3

10.1 Introducing Maven

10.1.1 Convention over configuration

10.1.2 Strong dependency management

10.1.3 Maven build lifecycles

10.1.4 Plugin based architecture

10.1.5 The Maven Project Object Model (POM)

10.2 Setting up a Maven project

10.3 Introduction to Maven plugins

10.3.1 Maven compiler plugin

10.3.2 Maven surefire plugin

10.3.3 HTML JUnit reports with Maven.

10.4 Putting it all together

10.5 Maven challenges

10.6 Summary

11 Running JUnit tests from Gradle 5

11.1 Introducing Gradle

11.2 Installing Gradle

11.3 Creating Gradle tasks

11.4 Setting up a Gradle project

11.5 Using Gradle plugins

11.6 Creating a Gradle project from the scratch and testing it with JUnit 5

11.7 Comparing Gradle and Maven

11.8 Summary

12 JUnit 5 IDE support

12.1 Introducing IDEs

12.2 Using JUnit 5 with IntelliJ IDEA

12.3 Using JUnit 5 with Eclipse

12.4 Using JUnit 5 with NetBeans

12.5 Comparing JUnit 5 usage in IntelliJ, Eclipse and NetBeans

12.6 Summary

13 Continuous integration with JUnit 5

13.1 Continuous integration testing

13.2 Introducing Jenkins

13.3 Jenkins customization

13.4 Practicing continuous integration in a team

13.5 Configuring Jenkins

13.6 Working on tasks in a continuous integration environment

13.7 Summary

Part 4: Working with modern frameworks and JUnit 5

14 JUnit 5 extension model

14.1 Introducing JUnit 5 extension model

14.2 Creating JUnit 5 extensions

14.2.1 Introducing logging capabilities

14.3 Implementing JUnit 5 tests using the available extension points

14.3.1 Persisting the passengers to a database

14.3.2 Checking the unicity of the passengers

14.3.3 Implementing conditional tests execution

14.4 Registering JUnit 5 extensions

14.5 Summary

15 Presentation Layer Testing

15.1 Choosing a Testing Framework

15.2 Introducing HtmlUnit

15.2.1 A live example

15.3 Writing HtmlUnit tests

15.3.1 HTML Assertions

15.3.2 Testing for a specific web browser

15.3.3 Testing more than one web browser

15.3.4 Creating stand-alone tests

15.3.5 Testing forms

15.3.6 Testing web navigation and frames

15.3.7 Testing JavaScript

15.4 Introducing Selenium

15.5 Writing Selenium Tests

15.5.1 Testing for a specific web browser

15.5.2 Testing navigation using a web browser

15.5.3 Testing more than one web browser

15.5.4 Testing Google search and navigation using different web browsers

15.5.5 Testing the authentication scenario to a website

15.6 HtmlUnit vs. Selenium

15.7 Summary

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 with JUnit 5

22 Implementing a test strategy pyramid with JUnit 5

About the Technology

If you’re a Java developer, you have to learn JUnit, the de facto standard for testing Java applications for over a decade. JUnit 5 is a complete overhaul of this leading Java unit testing framework, filled with new tools that make it easier than ever to write effective tests. JUnit 5 brings more granularity and avoids the need to import an entire library, allows multiple runners to work simultaneously and, best of all, allows developers to make full use of the new language features of Java 8 and beyond.

About the book

JUnit in Action, Third Edition is a fully revised guide to unit testing Java applications with the latest version of JUnit. It’s full of hands-on techniques for solving real-world testing problems, such as using mocks for testing isolation, automating your testing, and test-driven development. You’ll also get to grips with more than just testing tools, thanks author Cătălin Tudose’s testing strategy pyramid, which lays out how to break your testing down into different layers — from unit testing right through to system and acceptance testing. Practical examples demonstrate each new JUnit 5 feature, such as new architecture, as well as nested tests, tagged tests, dynamic tests, and dependency injection. With full coverage of migrating your JUnit 4 applications to JUnit 5, and integrating JUnit with other build tools and continuous integration tools, JUnit in Action sets you on the path to bug-free code.

What's inside

  • Introduction to unit testing
  • Connecting JUnit 5 with build tools such as Maven or Gradle
  • Working with JUnit 5 extensions
  • Develop Test Driven Development and Behavior Driven Development applications
  • Migrating from JUnit 4 to 5

About the reader

For intermediate Java developers.

About the authors

Cătălin Tudose has a PhD in Computer Science, and over 15 years experience as a Senior Java Developer and Technical Team Lead. He works as a Java and Web Technologies Expert at Luxoft Romania, and as a professor at the Faculty of Automation and Computers in Bucharest. Petar Tahchiev, Felipe Leme, and Gary Gregory authored the second edition of JUnit in Action, and Vincent Massol was the author of the first edition.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $59.99 pBook + eBook + liveBook
includes previous edition eBook
MEAP eBook $47.99 pdf + ePub + kindle + liveBook
includes previous edition eBook
Prices displayed in rupees will be charged in USD when you check out.

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks