My build.gradle is configure like this:
apply plugin: 'java'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
repositories {
mavenCentral()
}
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0-M1")
testRuntime("org.junit.vintage:junit-vintage-engine:5.0.0-M1")
}
and a simple test like this:
public class JUnit5Test {
@Test
void test() {
}
}
When I execute my test, I see this in the console:
Test run finished after 76 ms
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful]
[ 0 tests failed ]
BUILD SUCCESSFUL
But there's nothing in the test report:
What do I do wrong? How can I integrate JUnit 5 results into the test report windows ?
I'm using Intellij 2016.2
When you execute the tests with gradle you get the results printed to the console as shown above. If you want to see the results in Idea's test report window you can simply execute the test within the IDE using the brand new built-in support:
https://www.jetbrains.com/idea/whatsnew/#v2016-2-java
Hope that helps - regards matthias
As of version 2016.2 this is now fully supported. It works just like it does with junit4 test results: you do need the JUnit plugin activated (see under File menu, Settings.. item, Plugins section).
Don't use the Gradle tool window to start your test, use the IDE tools directly. These include:
- Clicking the margin icon (looks like a green circle with a small "play" icon superimposed) and selecting "Run" or "Debug"
- Right-clicking the class or method name and selecting "Run" or "Debug"
- Using the "Run" menu, any menu item with "Run" or "Debug"
- Selecting the test class in the run configuration toolbar dropdown, then clicking the green "Play" icon.
Note that currently, @TestFactory
methods cannot be run this way. This can be very confusing if you've got classes with only @TestFactory
methods! You can work around this by adding a dummy @Test
method to classes containing @TestFactory
methods, then run the class as described above. The @TestFactory
methods are found correctly when the entire class is run.
As I understand it (and I'm still learning), you need to use the JUni4 based runner in order to run & view the results in Intellij (src JUnit5 docs). To do this you would need to enable the junit-platform-runner artifact in you gradle.build file. On that note, the gradle.build file examples presented seem a bit more complicated than what you have presented.
I finally got JUnit5 up in Intellij by starting with the gradle.build file shown in the junit5-gradle-consumer example, playing with it, banging my head, etc, until I got it working. There are still differences when I run the tests in the console with gradle and running them in Intellij. Sometimes Intellij will not identify a test class as a test, particularly for nested tests. But, I am able to right click on the individual classes and run them in Intellij.
Below is my hack of a gradle.build file that got things working in intellij (including what I commented out & added).
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
}
}
repositories {
mavenCentral()
}
ext.junit4Version = '4.12'
ext.junitVintageVersion = '4.12.0-M2'
ext.junitPlatformVersion = '1.0.0-M12'
ext.junitJupiterVersion = '5.0.0-M2'
ext.junitPlatformConsoleVersion = '1.0.0-M2'
ext.log4JVersion = '2.5'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.junit.platform.gradle.plugin'
jar {
baseName = 'x2'
version = '1.0.0-SNAPSHOT'
}
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.compilerArgs += '-parameters'
}
junitPlatform {
// platformVersion '1.0.0-SNAPSHOT'
engines {
include 'junit-jupiter', 'junit-vintage'
// exclude 'custom-engine'
}
tags {
// include 'fast'
// exclude 'slow'
}
// includeClassNamePattern '.*Test'
// enableStandardTestTask true
// reportsDir "build/test-results/junit-platform" // this is the default
// logManager 'org.apache.logging.log4j.jul.LogManager'
}
dependencies {
// JUnit Jupiter API and TestEngine implementation
testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testCompile("org.junit.platform:junit-platform-console:${junitPlatformConsoleVersion}")
testRuntime("org.junit.platform:junit-platform-console:${junitPlatformConsoleVersion}")
// added to run via test suite
testCompile("org.junit.platform:junit-platform-runner:${junitPlatformConsoleVersion}")
testRuntime("org.junit.platform:junit-platform-runner:${junitPlatformConsoleVersion}")
// If you also want to support JUnit 3 and JUnit 4 tests
//testCompile("junit:junit:${junit4Version}")
//testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}")
// testRuntime("org.apache.logging.log4j:log4j-core:${log4JVersion}")
// testRuntime("org.apache.logging.log4j:log4j-jul:${log4JVersion}")
}
task wrapper(type: Wrapper) {
distributionUrl = 'https://services.gradle.org/distributions/gradle-2.14.1-bin.zip'
}
Hope this helps.