Testing with Gradle Java Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 34: Line 34:
Also see [[Maven_Surefire_Plugin#Configuration_Example|Maven Surefire Configuration Example]].
Also see [[Maven_Surefire_Plugin#Configuration_Example|Maven Surefire Configuration Example]].
==Test Execution Mechanics Logging Output==
==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:
<syntaxhighlight lang='text'>
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]
</syntaxhighlight>


The "testLogging" property represents a set of options that control which '''test events''' are logged and at what level.  
The "testLogging" property represents a set of options that control which '''test events''' are logged and at what level.  

Revision as of 22:21, 23 November 2018

External

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.

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