Tests

The Test task allows you to run any supported test library — JUnit, JUnit Platform or TestNG.

You can filter or skip the specified tests.

Test configuration example

There are some properties of Task to control how the test process is launched.

property description
maxParallelForks Allows to run tests in parallel. Default value 1. Useful on a multi-core CPU. Make sure your tests are properly isolated from one another.
forkEvery Specifies the maximum number of test classes that Gradle should run on a test process before its disposed of and a fresh one created. Default value is 0 (no maximum).
ignoreFailures If this property is true, Gradle will continue with the project’s build once the tests have completed, even if some of them have failed. Default value is false.
failFast Set this to true if you want the build to fail and finish as soon as one of your tests fails. Default value is false.
testLogging Represents a set of options that control which test events are logged and at what level.

command line

You can run tests from command line.

// Executes all detected tests
gradle test

// Executes all detected tests with failFast option
gradle test --fail-fast

# Executes all tests in SomeTestClass
gradle test --tests SomeTestClass

# Executes a single specified test in SomeTestClass
gradle test --tests SomeTestClass.someSpecificMethod

gradle test --tests SomeTestClass.*someMethod*

JUnit 5

To enable JUnit5 tests use following configuration.

repositories {
    mavenCentral()
}

dependencies {
    // see actual version
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:5.7.2")
}

tasks.test  {
    useJUnitPlatform()
}