JUnit 5 Overview
What Is JUnit?
JUnit is a framework for unit testing in Java. It can create object instances, execute logic, compare actual results with expected values, and test file, network, or database interactions.
JUnit provides assertion-related methods that check whether a test result is true or false, null, or the same object. It also provides the @Test annotation to mark test methods, and lifecycle annotations such as Before and After to define behavior before and after tests.
JUnit is an open source testing framework for Java, developed by Erich Gamma, one of the GoF authors of “Design Patterns”, and Kent Beck, who is well known for XP. JUnit provides a simple way to express the intended behavior in code and verify that the code works as expected. Originally, JUnit could be used independently of IDEs and development tools, either from the command line or in a GUI environment.
Unit Tests and Functional Tests
Unit Tests
A unit test checks whether a basic unit of a program works correctly according to its internal design specification. In Java, the basic unit is a class, so you test whether the methods included in each class work correctly. Therefore, the scope of a unit test is very limited.
Functional Tests
A functional test checks whether the entire software works correctly. It treats the whole software system as a black box and tests each feature from the user’s point of view. Functional tests are usually performed by a separate test team and use tools and techniques different from those used during development.
JUnit 5 Support
- JUnit 4
- Java 1.4 or later
- JUnit 5
- JUnit 5 requires Java 1.8 or later
JUnit 5 Structure
JUnit 4 was an all-in-one structure, but JUnit 5 is divided into Platform, Jupiter, and Vintage.
- Base module for running test frameworks
- JUnit Platform: Provides the foundation for running test frameworks on the JVM and also provides APIs for test development.
- Concrete test framework modules
- JUnit Jupiter: Provides a
TestEnginethat combines the new programming model and extension model for JUnit 5 tests and extensions. - JUnit Vintage: A
TestEnginefor running JUnit 4 and JUnit 3 tests for backward compatibility.
- JUnit Jupiter: Provides a