Testing with Gradle Java Plugin
External
- Gradle Docs - Testing in Java & JVM projects https://docs.gradle.org/current/userguide/java_testing.html
Internal
Overview
Testing is performed by the "test" task (implemented by Test), which automatically detects and executes all unit tests in the test source set and generates a report once test execution is complete. JUnit and TestNG are both supported.
Configuring the "test" Task
Use a script block in build.gradle:
test {
useJUnit()
maxHeapSize = '1G'
}
Passing System Properties to Tests
test {
...
systemProperty 'rootDir', "${rootDir}"
...
}
Also see Maven Surefire Configuration Example.
Show stdout and stderr of the Test JVM on the Console
test {
testLogging.showStandardStreams = true
}
Test Execution Mechanics Logging Output
A quick way to generate Gradle test execution code logging is to start the test task with --debug:
gradle test --debug
Running gradle test in this mode could prove helpful to troubleshooting test logging configuration issues such as:
14:18:50.105 [DEBUG] [TestEventLogger]
14:18:50.105 [DEBUG] [TestEventLogger] Gradle Test Executor 1 STARTED
14:18:50.111 [DEBUG] [TestEventLogger]
14:18:50.111 [DEBUG] [TestEventLogger] com.example.SomeTests STARTED
14:18:50.186 [DEBUG] [TestEventLogger]
14:18:50.186 [DEBUG] [TestEventLogger] com.example.SomeTests STANDARD_ERROR
14:18:50.186 [DEBUG] [TestEventLogger] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
14:18:50.188 [DEBUG] [TestEventLogger] SLF4J: Defaulting to no-operation (NOP) logger implementation
14:18:50.188 [DEBUG] [TestEventLogger] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
14:18:50.948 [DEBUG] [TestEventLogger]
The "testLogging" property represents a set of options that control which test events are logged and at what level.
test {
testLogging {
...
}
}
For more details see TestLoggingContainer.
TODO
TODO process https://docs.gradle.org/current/userguide/java_testing.html