JUnit 5 Architecture

Posted By : Amarchand Kushwaha | 30-Jan-2020

testing Java

Loading...

JUnit 5, the next-gen unit testing framework, has a very different architecture compared to its precursors, Junit 3 & 4. With JUnit 5, the project is first split into three sub-projects: Jupiter, Platform, and Vintage.They communicate via published APIs, which allow libraries and tools to inject customized behavior. Each sub-project is split into several artifacts to separate concerns and guarantee maintainability.

Separating Concerns:

1. An API to write tests against.

2. A mechanism to discover and run tests.

a. A mechanism to discover and run a specific variant of tests

b. A mechanism to orchestrate the specific mechanisms

c. An API between them

Splitting JUnit 5:

The project is split into three sub-projects: Jupiter, Platform, and Vintage.

1. JUnit Jupiter

-The API against which we write tests and the engine that understands it.

2. JUnit Vintage

-Implements an engine that allows you to run tests written in JUnit 3 & 4 with JUnit 5.

3. JUnit Platform

-Contains the engine API and provides a uniform API to tools, so they can run tests.

Architecture:

JUnit 5 architecture is the result of that distinction. These are some of its artifacts below:

junit-jupiter-api:

It is the API against which developers write tests. It contains all the annotations, assertions, etc. that we saw when we discussed Junit 5 basics.

junit-jupiter-engine:

It is an implementation of the junit-platform-engine API that runs JUnit 5's tests.

junit-vintage-engine:

It is an implementation of the junit-platform-engine API that runs tests written with JUnit 3 and 4. The JUnit 4 artifact junit-4.12 acts as the API that the developer implements their tests against. It also contains the main functionality of how to run the tests. The engine could be seen as an adapter of JUnit 3/4 for version 5.

amar

pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=

"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.demo</groupId>

<artifactId>Junit-Basics</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>Junit-Basics</name>

<properties>

<maven.target.compiler>1.8</maven.target.compiler>

<maven.compiler.source>1.8</maven.compiler.source>

<junit.jupiter.version>5.4.0</junit.jupiter.version>

</properties>

<dependencies>

<dependency>

<groupId>org.junit.jupiter</groupId>

<artifactId>junit-jupiter-engine</artifactId>

<version>${junit.jupiter.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.junit.jupiter</groupId>

<artifactId>junit-jupiter-api</artifactId>

<version>${junit.jupiter.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.junit.platform</groupId>

<artifactId>junit-platform-commons</artifactId>

<version>1.5.2</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine -->

<dependency>

<groupId>org.junit.vintage</groupId>

<artifactId>junit-vintage-engine</artifactId>

<version>${junit.jupiter.version}</version>

<scope>test</scope>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<artifactId>maven-surefire-pugin</artifactId>

<version>2.22.1</version>

</plugin>

</plugins>

</build>

</project>

Conclusion:

We have seen how the JUnit 5's architecture divides the API for writing tests and the engines for running them into separate parts, splitting the engines into an API, a launcher using it, and implementations for different test frameworks. It gives users lean artifacts to develop tests against (because they only contain the APIs), test frameworks that only have to implement an engine for their API, and build tools that have a stable launcher to orchestrate test execution.

We are an ERP development company that enables enterprises to streamline operations and drive returns, using next-gen technologies, with our development services. Our services include developing applications for all your ERP needs from CRM, WFM, and HRM to eCommerce, accounting and wealth management software. We use an extensive tech stack including Javascript and JUnit 5 to develop end to end customized software for your enterprise. Get in touch with our experts to know more about how you can implement these technologies into your business.