Last updated: February 12, 2019
Table of Contents
Migrating From JUnit 4
- JUnit5 Assertion Migration Strategy introduces a strategy that helps you to migrate your assertions from JUnit 4 to JUnit 5.
- JUnit 5 vs JUnit 4 is a hands-on guide that describes the differences between JUnit 4 and 5. It also provides a list of blog posts that help you to get started with JUnit 5.
- Migrating from JUnit 4 to JUnit 5 is a practical post that identifies the differences between JUnit 4 to JUnit 5. This information helps you to migrate your existing tests from JUnit 4 to JUnit 5.
- Migrating to JUnit 5 describes how the author migrated the VocabHunter open source project from JUnit 4 to JUnit 5. This post describes how the author updated his (somewhat complex) Gradle build script and explains how he solved a few other problems such as mocking and passing JVM arguments to his test suite.
- JUnit 5 User Guide: 6. Migrating from JUnit 4 describes how you can run your existing tests with JUnit 5 and provides tips that help you to make the required changes to your existing tests.
- Porting Your Existing Tests to JUnit 5 is a hands-on guide that helps you to modify your existing tests to use JUnit 5.
JUnit 5 Architecture
- JUnit 5 – Architecture is an excellent blog post that provides a comprehensive description of the JUnit 5 architecture. The interesting thing about this blog post is that also describes the reasons behind the design decisions made by JUnit 5 team.
Using Maven and Gradle
- How to avoid "No tests were found" when using JUnit 5 with Groovy helps you avoid a very common mistake that is often made by people who are familiar with the Spock Framework.
- JUnit 5 Tutorial: Running Unit Tests With Maven describes how you can get the required dependencies with Maven and create a Maven project that runs your unit tests.
- JUnit 5 Tutorial: Running Unit Tests With Gradle describes how you can get the required dependencies with Gradle and create a Gradle project that runs your unit tests.
- Why Your JUnit 5 Tests Are Not Running Under Maven explains why you might not be able to run JUnit 5 tests with Maven if you are using Maven 3.6.0. Obviously, this post helps you to solve your problem.
Getting Started With JUnit 5
- The top five reasons you should be using JUnit 5 right now explains the benefits of using JUnit 5 and reveals (surprisingly) five reasons why you should give it a shot.
- The five coolest new features of JUnit 5 introduces five features that should convince you to start using JUnit 5.
- A Look at JUnit 5’s Core Features & New Testing Functionality is a practical blog post that provides a quick introduction to the new features of JUnit 5.
- Introducing JUnit 5, Part 1 - The JUnit 5 Jupiter API is a very good blog post that provides an overview of the JUnit 5 architecture and helps you to write your first unit tests with JUnit 5.
- Introducing JUnit 5, Part 2 - JUnit 5 Vintage and the JUnit Jupiter Extension Model is a very good blog post that describes what JUnit vintage and explains how it works. This post also provides an introduction to the JUnit 5 extension model and explains how you can use it for writing dynamic and parameterized tests.
- JUnit 5 - Quick Tutorial is a practical blog post that describes how you can get the required dependencies and write your first tests with JUnit 5.
- JUnit 5 Tutorial: Writing Our First Test Class describes how you can use setup and teardown methods, and add test method to your test class. Note that this tutorial assumes that you have no previous experience from JUnit 4.
- Testing on Android using JUnit 5 helps you to write tests for an Android application with Kotlin and JUnit 5.
- What's new in JUnit 5 describes how you can migrate your existing tests from JUnit 4 to JUnit 5 and introduces the new features of JUnit 5.
- What's New in JUnit 5.1 provides a quick introduction to the new features of JUnit 5.1.
Writing Parameterized Tests
- How to Use JUnit 5
@MethodSource
Parameterized Tests With Kotlin describes how you can write parameterized tests that get the test data by invoking a factory method when you are using Kotlin and JUnit 5. - JUnit 5 - Parameterized Tests is an excellent blog post that describes how you can write parameterized tests with JUnit 5.
- JUnit 5 Tutorial - Writing Parameterized Tests is a comprehensive blog post that describes how you can write parameterized tests with JUnit 5.
- @ParameterizedTest with null values in @CvsSource explains how you can pass
null
values to your parameterized test when you provide the test data by using the@CsvSource
or@ValueSource
annotation. - Use null values in JUnit 5 parameterized tests describes how you can provide
null
values to parameterized tests by using the@MethodSource
annotation.
Writing Assertions
- JUnit 5 Tutorial - Writing Assertions With JUnit 5 Assertion API describes how you can write assertions with JUnit 5 assertion API, provide a custom error message that is shown if an assertion fails, and group assertions with JUnit 5.
- JUnit 5 Tutorial: Writing Assertions With Hamcrest describes how you can get the required dependencies with Maven and Gradle, write basic assertions with Hamcrest, combine multiple Hamcrest matchers, and provide a custom error message that is shown when an assertion fails.
- JUnit 5 Tutorial: Writing Assertions With AssertJ describes how you can get the required dependencies with Maven and Gradle, write basic assertions with AssertJ, write soft assertions with AssertJ, and provide a custom error message that is shown when an assertion fails.
Structuring Test Classes
- Encouraging Good Behavior with JUnit 5 Test Interfaces describes how you can add test methods to so called test interfaces and explains the benefits of this technique.
- JUnit 5 Tutorial: Writing Nested Tests describes how you can write nested tests with JUnit 5, and leverage setup and teardown methods in your nested tests.
- Structured JUnit 5 testing explains how you can structure your test cases by using nested inner classes and the given-when-then format.
Using Test Doubles
Mockito
- Mockito and JUnit 5 – Using ExtendWith describes how you can use Mockito annotations (such as the
@Mock
annotation) with JUnit 5.
WireMock
- WireMock Tutorial: Introduction provides a quick introduction to WireMock. After you have read this blog post, you can identify the key features WireMock, you understand when you should use it, and you can get the required dependencies with Maven and Gradle.
- WireMock Tutorial: Configuration describes how you can configure WireMock from the scratch. After you have read this blog post, you can configure the used WireMock server, you know how you can start the WireMock server before a test method is run, and you can stop the WireMock server after a test method has been run.
- WireMock Tutorial: Request Matching, Part One provides an introduction the request matching support of WireMock. This blog post helps you to understand how request matching works, and describes how you can specify expectations for request methods and request urls.
- WireMock Tutorial: Request Matching, Part Two describes how you can use the WireMock's request matching support when you want specify expectations for cookies, HTTP headers, and request parameters.
- WireMock Tutorial: Request Matching, Part Three describes how you can specify expectations for the JSON document that is received by your WireMock server.
- WireMock Tutorial: Request Matching, Part Four describes how you can specify expectations for the XML document that is received by your WireMock server.
- WireMock Tutorial: Introduction to Stubbing describes how you can ensure that your WireMock server returns a configured HTTP response when it receives a specific HTTP request.
Filtering the Invoked Tests
- Conditionally Disabling and Filtering Tests in JUnit 5 describes how you can disable tests when a specific condition is met and divide your test suite into smaller groups by using tags.
- Creating Test Stages With JUnit describes how you can divide your tests into multiple categories that can be run separately when you are using either JUnit 4 or JUnit 5.
Writing Integration Tests
- Running your JUnit 5 integration test with an embedded elasticsearch on a random port (and optionally Spring Boot) explains how you can start an ElasticSearch server before your integration test is run.
Writing Extensions
- A Guide to JUnit 5 Extensions provides a quick introduction to the JUnit 5 extension model and describes how you can write your first JUnit 5 extension.
- JUnit 5 - Extension Model is an excellent blog post that describes the JUnit 5 extension model. The best part of this blog post is that the author identifies the reasons behind the technical decisions made by the JUnit 5 team.
- Testing System.exit() with JUnit 5 describes how you can write a custom JUnit 5 extension which allows you write tests for
System.exit()
.
Extensions
- A JUnit 5 extension for Selenium WebDriver
- Database Rider JUnit 5 extension (Use DbUnit with JUnit 5)
- Hoverfly extension
- JUnit Extension provides JUnit 5 equivalents of common JUnit 4 rules such as
@ExpectedException
and@TemporaryFolder
. This project also offers a few other useful extensions that allow you to manipulate and access system properties, inject dummy objects into your tests, and debug the execution flow of your tests. - Spring TestContext Framework Extension for Spring 4.3
- WireMock Extension