Skip to content

JUnit 5: Using with Gradle

Kristina edited this page Nov 2, 2017 · 1 revision

JUnit 5 is setup a bit different then previous versions and is broken down into the following modules:

  • JUnit Platform
    • This is used for launching testing frameworks. It defines the TestEngine API for creating a testing framework. This also creates a console launcher to launch the testing framework from the command line and provides the build plugins for Gradle and Maven. A JUnit 4 based runner for running any JUnit 4 tests on the platform is included in this module.
  • JUnit Jupiter
    • API for writing tests using JUnit 5.
  • JUnit Vintage
    • This is an API for running JUnit 3 and JUnit 4 based tests on the testing framework.

You can find a list of all of the artifacts tied to these modules here.

To use JUnit with Gradle you need to add the JUnit Gradle plugin to your build.gradle file using the code below:

buildscript {
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.1'
	}
}

apply plugin: 'org.junit.platform.gradle.plugin' 

In order to be able to run test you need to have a test engine setup in the classpath in the build.gradle file:

dependencies {
	testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0")
	testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0")
}

You can read more about the using the Gradle plugin here

Clone this wiki locally