JUnit 5 Tutorial

This JUnit 5 tutorial teaches us how to write and run tests for our Java and Kotlin code. Eventually, we will learn to write unit, integration and end-to-end tests. In the future, we will also learn how to test Spring applications and how to use the Mockito mocking framework.

Currently, the tutorial consists of the following articles:

Getting Started

  • Getting Started with JUnit 5 - Learn to write your first JUnit 5 test. Start here if you are completely new to testing.

  • JUnit 5 Assertions - Learn to write JUnit 5 assertions to verify tests results.

  • JUnit 5 Test Lifecycle - Learn to to run code before and after each test or all tests in the test class.

  • JUnit 5 Parameterized tests – Learn to remove duplication from test code by writing JUnit 5 parameterized tests. Use different sources of parameters to run the same test several times using different input.

  • JUnit 5 Maven Example – Configure Maven dependencies for writing JUnit 5 tests and Maven Surefire plugin for running them.

  • JUnit 5 Gradle Example – Configure Gradle dependencies for writing JUnit 5 tests and JUnit Gradle plugin for running them.

  • JUnit 5 with Kotlin - Learn how to write JUnit 5 tests in the Kotlin language.

Also, if you are already familiar with JUnit 4, you might be interested in:

  • Migrating from JUnit 4 to JUnit 5 – Learn the steps required for migrating from JUnit 4 to JUnit 5. Run your existing JUnit 4 tests along with JUnit 5, or migrate the code to the new version.