question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestEngine with ID 'junit-jupiter' failed to discover tests

See original GitHub issue

Hi,

I try to implement instrumented unit tests. I work with Android Studio 3.0.1

My top Level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.21'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.30"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My app-level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: "de.mannodermaus.android-junit5"

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.todo.app"
        minSdkVersion 26
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    testOptions {
        // Configuration closure added by the plugin;
        // all configurable parameters related to JUnit 5 can be found here
        junitPlatform {
            // The JUnit Jupiter dependency version to use
            jupiterVersion "5.0.3"

            // The JUnit Vintage Engine dependency version to use
            vintageVersion "4.12.2"

            // Options related to running unit tests with JUnit 5.
            unitTests {
                // Whether or not JUnit 5 test tasks should be affected by
                // JVM Arguments, System Properties & Environment Variables
                // declared through "unitTests.all" closures
                applyDefaultTestOptions true
            }

            // Options related to running instrumented tests with JUnit 5.
            // This is an incubating feature which utilizes the backwards-compatibility
            // of the JUnit Platform in order to enhance the default Test Instrumentation Runner
            // with new power. However, because of their experimental nature and steep minSdkVersion requirement,
            // they are turned off by default. If you choose to enable them, you also have to declare
            // the library dependency in your androidTest scope. Please refer to the "Setup"
            // section for more details.
            instrumentationTests {
                enabled true

                // The Android-Instrumentation-Test dependency version to use
                version "0.1.1"
            }
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.3'
    testCompile "org.mockito:mockito-core:2.13.0"

    // (Required) Writing and executing Unit Tests on the JUnit Platform.
    testImplementation junit5.unitTests()

    // (Optional) If you need "Parameterized Tests".
    testImplementation junit5.parameterized()

    // (Optional) For running tests inside Android Studio 3.x
    testCompileOnly junit5.unitTestsRuntime()

    androidTestImplementation junit5.instrumentationTests()
}

repositories {
    mavenCentral()
}

apply plugin: 'kotlin-android-extensions'

Under src/androidTest/java/com.myapp.app/ExempleInstrumentedTest my test:

package com.todo.app

import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class ExampleInstrumentedTest {

    @Test
    fun test() {

        // Read the data.
        assertEquals(true, true, "test")
    }
}

When I try to launch this test I got this error (on android studio):

févr. 01, 2018 7:48:50 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
AVERTISSEMENT: TestEngine with ID 'junit-jupiter' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.todo.app.ExampleInstrumentedTest

and

févr. 01, 2018 7:48:50 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
AVERTISSEMENT: TestEngine with ID 'junit-vintage' failed to discover tests
org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.todo.app.ExampleInstrumentedTest
Process finished with exit code 0
Empty test suite.

What is the problem ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
progonkpacommented, Mar 23, 2019

As you may now Android Studio is basically the same IDE as IntelliJ. I ran into this issue with IntelliJ Community Edition. I had the newest version of JUnit in my dependencies (5.4.1) which turned out to be an issue.

The error went away after switching to JUnit 5.3.2. I discoverd this version number by removing the JUnit dependencies and letting IntelliJ resolve the import statements.

3reactions
Leander250commented, Feb 19, 2021

I got the same problem using Spring Boot with the Gradle Spring Dependency Management plugin. This solved my issue without downgrading the Version to 5.3.2: https://stackoverflow.com/questions/54598484/gradle-5-junit-bom-and-spring-boot-incorrect-versions/54605523#54605523

Read more comments on GitHub >

github_iconTop Results From Across the Web

TestEngine with ID 'junit-jupiter' failed to discover tests - Stack ...
I had this issue when I upgraded the versions of JUnit from 5.7.0 to 5.8.2. Try with version 5.7.0 for org.junit.jupiter:junit-jupiter-api and ...
Read more >
TestEngine with ID 'junit-jupiter' failed to discover tests
TestEngine with ID 'junit-jupiter' failed to discover tests ... After upgrading to the latest EAP build, I cannot execute any JUnit 5 test...
Read more >
TestEngine with ID 'junit-jupiter' failed to discover tests #1422
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests at org.junit.platform.launcher.core.
Read more >
testengine with id 'junit-jupiter' failed to discover tests spring boot
TestEngine with ID 'junit-jupiter' failed to discover tests - Caused by: org.junit.platform.commons.JUnitException: ClassSelector resolution failed.
Read more >
Run as JUnit Test - Java Development Tools (JDT) - Eclipse
JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found