JUnit 5 with Gradle Dependency

By | December 8, 2019

In this post we will learn how to configure Gradle Dependency for JUnit 5 and how to use them to create and execute JUnit Tests

To execute JUnit 5 tests using Gradle, we need minimum two dependencies.

1. JUnit Jupiter Engine Dependency

junit-jupiter-engine has internally dependency on and junit-platform-engine and junit-jupiter-api so if you add junit-jupiter-engine dependency then it will bring all three dependencies into class path.

junit-jupiter-api has all Junit annotations to write tests and extensions and junit-platform-engine has test engine implementation which is required at runtime to run the tests.

2. JUnit Platform Runner Dependency

We usually need junit-platform-runner for executing JUnit tests and test suites on JUnit Platform environment.

As junit-platform-runner is internally dependents on junit-platform-launcher  and junit-platform-suite-api  so if you add junit-platform-runner  dependency then it will bring all three dependencies into class path.

Complete JUnit 5 Gradle Project Example

Project Structure

Utility Class for that we have to write JUnit Test:

JUnit Test class

build.gradle

Right click on JUnit Class and choose Run As -> JUnit Test

Output of above JUnit Project

You may also like:
Junit 5 Architecture
JUnit 5 Annotations
JUnit 5 Maven Dependency

That’s all about JUnit 5 with Gradle Dependency
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *