2

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?

  • this works for me https://stackoverflow.com/a/50558072/51292 – Ray Tayek Dec 02 '18 at 06:42
  • my example was for gradle 4.7 – Ray Tayek Dec 02 '18 at 06:46
  • I would recommend including entire (minimal) build.gradle file in the question, otherwise it is difficult to understand your issue. Even better if you could make a GitHub repository with sample project that illustrates your problem. BTW, what Gradle version do you use? – Neeme Praks Dec 07 '18 at 11:07

1 Answers1

1

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.

kaiya
  • 271
  • 1
  • 3
  • 16