What’s This Course About?

Get introduced the JUnit 5 testing framework for Java.

Introduction

Java developers may not have experience using Spring or the Hibernate framework, but they should know about JUnit. As Java’s de facto unit testing framework, JUnit is a popular choice for developers. Despite the emergence of new unit testing frameworks like TestNG, JUnit is still the first choice for many new projects for unit testing. JUnit 55 was released on September 10,201710, 2017. It added many new features, but it can still run test cases written with JUnit 44 and JUnit 33.

What’s JUnit 5?

JUnit 5 consists of three subprojects:

  • JUnit Platform is the foundation to launch testing frameworks on the JVM.

  • JUnit Jupiter provides the new programming model and extension model of JUnit 5.

  • JUnit Vintage run JUnit 4 and JUnit 3 tests on the JUnit Platform. It requires JUnit 4.12 or later to be present on the classpath or the module path.

JUnit Jupiter and JUnit Vintage are two different implementations based on the JUnit Platform. Each subproject has one or many modules. Artifacts of these modules can be used in other cases. We’ll use JUnit 5 version 5.8.2 in this course.

Intended audience

Unit testing has evolved into a fascinating blend of design, coding, and debugging. This course will help us gain value from our testing. Even if you’re new to the concepts, this course will help you learn most of the unit testing.

Prerequisites

The prerequisites for this course are:

  • A working knowledge of the Java language.
  • A basic understanding of unit testing, external dependencies, and libraries.

Advantages of JUnit 5 over JUnit 4

Let’s view the advantages of JUnit 5 over JUnit 4:

JUnit Version Comparison

JUnit 4

JUnit 5

In JUnit 4, the entire framework was stored in a single jar library, which meant that even if only a single feature was required, the entire library had to be imported.

In JUnit 5, we get more granularity and can import only what’s required.



A test runner can only execute tests in JUnit 4 one at a time (SpringJUnit4ClassRunner or Parameterized, for example).

JUnit 5 allows multiple runners to work simultaneously.

JUnit 4 doesn’t work with Java 8; therefore, it misses out on many of those features.

JUnit 5 capitalizes on Java 8 features.