android-junit5: TestEngine with ID 'junit-jupiter' failed to discover tests
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 ?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 19 (6 by maintainers)
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.
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