简体   繁体   中英

Running JUnit Test works but Gradle Tests does not. How to fix?

I am writing a game in libGDX using IntelliJ. I am writing the tests and having difficulty running them using gradle test . I get the error:

error: package org.junit.jupiter.api does not exist

org.junit.jupiter:junit-jupiter-api:5.1.0 is in the Gradle dependencies. I have included repositories(mavenCentral()) in build.gradle. I have followed the documentation for Gradle 4.6 and JUnit 5 so also have the following:

test{
    useJUnitPlatform()
}

However this seems to make no difference. Whenever I change the dependencies it affects whether I can run the JUnit tests so I know it is using them. It is just that when I run gradle test I get that error. How can I fix this?

I had the same problem, but it went away when i added that dependency down there. Might be that

allprojects {
    apply plugin: "java"

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }

    dependencies {
        compile 'org.junit.jupiter:junit-jupiter-api:5.1.0'
    }
}

Since we do not know how you added junit to the build.gradle, maybe leave a comment to let us know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM