adamjhawley
adamjhawley

Reputation: 31

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?

Upvotes: 2

Views: 1614

Answers (1)

kaiya
kaiya

Reputation: 312

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.

Upvotes: 1

Related Questions