Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find method useJUnitPlatform for test task in gradle

Tags:

java

gradle

I am trying to configure gradle to run JUnit 5 tests. however, when I try to add useJUnitPlatform() in my gradle file to enable JUnit 5 support as Directed here gradle docs I am getting the error

Could not find method useJUnitPlatform() for arguments [] on task ':test' of type org.gradle.api.tasks.testing.Test.

Here is my Gradle File

    apply plugin: 'java'

group 'com.notif'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
    maven {
        url 'https://packages.confluent.io/maven/'
    }
}

tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
        events "started", "skipped", "passed", "failed"
        showStandardStreams true
    }
}


dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
    testImplementation "org.mockito:mockito-core:2.21.0"
    implementation 'org.apache.kafka:kafka-streams:1.0.0-cp1'
    implementation 'org.apache.kafka:kafka-clients:1.0.0-cp1'
    implementation 'org.apache.avro:avro:1.8.2'
    implementation 'org.apache.logging.log4j:log4j-core:2.11.0'
    implementation 'org.apache.logging.log4j:log4j-api:2.11.0'
    implementation 'io.confluent:kafka-streams-avro-serde:4.1.0'
    implementation 'biz.paluch.logging:logstash-gelf:1.11.2'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6'
    implementation 'org.asynchttpclient:async-http-client:2.2.0'
    implementation 'org.apache.logging.log4j:log4j-jcl:2.11.1'
}

Any Idea why this is happening, am I missing any dependency

like image 760
B0rn2C0de Avatar asked Aug 24 '18 05:08

B0rn2C0de


People also ask

What is useJUnitPlatform?

useJUnitPlatform() Specifies that JUnit Platform should be used to discover and execute the tests.

What is test task in Gradle?

The test task automatically detects and executes all the unit tests in the test source set., Once the test execution is complete, it also generates a report. JUnit and TestNG are the supported APIs. The test task provides a Test. getDebug() method that can be set to launch to make the JVM wait for a debugger.

How do I run a single unit test in Gradle?

In Gradle, we can pass an --tests option to run a single unit test class.


2 Answers

If you are using IntelliJ it is worth checking which Gradle are you using for given project (can be wrapper, task, local). To do so go to Settings and search for Gradle. Then navigate to Build,Execution,Deployment -> Build Tools -> Gradle

like image 151
Kinmarui Avatar answered Oct 08 '22 08:10

Kinmarui


Here is how I fixed it. I had this test task in my build.gradle:

tasks.withType(Test) {
    useJUnitPlatform()
    testLogging {
        exceptionFormat "full"
        events "started", "skipped", "passed", "failed"
        showStandardStreams true
    }
}

And I had these dependencies (You might want to refresh gradle so it takes them into account):

dependencies {
  testCompile('org.junit.jupiter:junit-jupiter-api:5.4.0')
  testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.0')
  testRuntime('org.junit.vintage:junit-vintage-engine:5.4.0')
}

Then I used the gradle wrapper (I was using gradle 4.8) so it stays stable from one computer to another:

./gradlew clean build test
like image 30
Sylhare Avatar answered Oct 08 '22 07:10

Sylhare