Comments (19)
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.
from android-junit5.
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
from android-junit5.
For instrumented tests, can you check and share the output in Logcat around the time when the test is being executed? Usually, that can yield more info about what is failing your execution.
from android-junit5.
Feel free to re-open with more information, I'm closing this for now.
from android-junit5.
Sorry to highjack, but I am having the same issue:
Mar 24, 2018 12:38:10 AM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: 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
at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:70)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.lambda$resolveSelectors$2(DiscoverySelectorResolver.java:59)
at java.util.ArrayList.forEach(ArrayList.java:1251)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:58)
at org.junit.jupiter.engine.JupiterTestEngine.resolveDiscoveryRequest(JupiterTestEngine.java:68)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:61)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:62)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Mar 24, 2018 12:38:10 AM org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: 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
at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71)
at java.util.Optional.orElseThrow(Optional.java:290)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:70)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1376)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.vintage.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:30)
at org.junit.vintage.engine.discovery.VintageDiscoverer.collectTestClasses(VintageDiscoverer.java:67)
at org.junit.vintage.engine.discovery.VintageDiscoverer.discover(VintageDiscoverer.java:54)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:65)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:62)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
from android-junit5.
Not sure if you get notified about a reply to a closed issue, so... @mannodermaus (sorry)
from android-junit5.
Can you share your build.gradle
config for the plugin? Specifically, I'd like to know what versions of the plugin / the instrumentation library you're pulling in. There has been quite a lot of development recently, and I'm wondering if upgrading to the latest and greatest will already do the trick for you.
from android-junit5.
Here they are:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.31"
// 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
}
...and...
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
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 {
junitPlatform {
jupiterVersion "5.0.3"
vintageVersion "4.12.2"
unitTests {
applyDefaultTestOptions true
}
instrumentationTests {
enabled true
version "0.1.1"
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation junit5.unitTests()
testImplementation junit5.parameterized()
testCompileOnly junit5.unitTestsRuntime()
androidTestImplementation junit5.instrumentationTests()
testImplementation 'org.assertj:assertj-core:3.8.0'
}
from android-junit5.
Can you remove your instrumentationTests.version
declaration? By default it will always use the latest available version, which is 0.2.1
right now. Lots of bugfixes from the version you're pulling in, so let me know if the problem persists after upgrading that library!
from android-junit5.
No luck. Same error :(
from android-junit5.
I tried digging deeper into the stacktrace, and it seems to fail in ReflectionUtils.loadClass(). None of the patterns match the class name, and it falls back to // Fallback to standard VM class loading return Optional.of(classLoader.loadClass(name));
which fails, and I can't see why as the implementation is not there.
from android-junit5.
Can you verify that com.todo.app.ExampleInstrumentedTest.class
exists in the build folder? Also, not sure if this is necessary or related, but I noticed that you don't declare the com.android.support.test:runner
dependency in your build.gradle, yet reference the AndroidJUnitRunner
correctly - the instrumentation test library for JUnit 5 hooks into the support test library using specific APIs in AndroidJUnitRunner
. Lastly, check if declaring Java 8 as both the compile and target language versions will do anything to improve the situation.
from android-junit5.
I did not see com.todo.app.ExampleInstrumentedTest.class
in the build folder before the changes, and sadly not after the changes you suggested. Here is a screenshot of the build/tmp folder contents. Please tell me if I'm looking in the wrong place.
Updated gradle files to reflect your suggestions:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.31"
// 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
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
and
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
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 {
junitPlatform {
jupiterVersion "5.0.3"
vintageVersion "4.12.2"
unitTests {
applyDefaultTestOptions true
}
instrumentationTests {
enabled true
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation junit5.unitTests()
testImplementation junit5.parameterized()
testCompileOnly junit5.unitTestsRuntime()
androidTestImplementation junit5.instrumentationTests()
testImplementation 'org.assertj:assertj-core:3.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
}
from android-junit5.
Compiled Kotlin androidTest classes are found in build/tmp/kotlin-classes/<debug>AndroidTest
. Try assembling the Android instrumentation tests explicitly with ./gradlew assembleAndroidTest
. In general, kotlinc not compiling Kotlin files is outside of the scope of this plugin, and I can't reproduce this on the sample project:
from android-junit5.
Strange. That compiled without issues from the console. However, I still could not run the tests due to the same error.
from android-junit5.
@vasticles Where are you at now with this issue, i'm having the same problem
from android-junit5.
@EbenezerGH I ended up giving up and going back to JUnit4 for instrumented tests
from android-junit5.
@vasticles I did the same
from android-junit5.
I encountered the same problem when I try to unit test with Spock and Groovy by the tutorial https://www.baeldung.com/groovy-spock
Accidently, I solved it by add gmavenplus plugin.
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
This is my all pom.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redfrog</groupId>
<artifactId>spock-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.7</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.0-groovy-3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
from android-junit5.
Related Issues (20)
- Instrumented Testsuites run on JUnit4 Runner HOT 1
- Might be better to migrate CI to Github Actions
- Add support for Gradle Plugins DSL HOT 2
- org.junit.runners.model.InvalidTestClassError starting with Android Studio Dolphin | 2021.3.1 HOT 8
- Build broken when using kotlin 1.7.21 HOT 1
- Clarification with regards to JaCoCo HOT 2
- AGP 8.0.0-alpha10 HOT 6
- Various 'Unable to resolve' log messages for Android tests HOT 4
- Parallel concurrent execution of instrumentation tests HOT 6
- NoClassDefFoundError: org/jetbrains/kotlin/gradle/plugin/KotlinPluginKt with Kotlin 1.8.20 HOT 5
- `@Tag` at the class level results in test number mismatch HOT 6
- NoSuchMethodError: 'org.gradle.api.provider.Property org.gradle.api.reporting.ConfigurableReport.getOutputLocation()' on Gradle 7.5.1 HOT 3
- Is it possible to run junit5 tests with robolectric? HOT 5
- Encountering problems when trying to integrate the plugin HOT 1
- Log not working with ParameterizedTest HOT 1
- Support per-test log display for JUnit 5 instrumentation tests HOT 4
- Readme should include apply plugin for legacy syntax HOT 1
- "Expected N+1 tests, received N" caused by fun with @TestTemplate HOT 4
- Invalid test names for repeated and parametrized tests HOT 8
- Usage of ComposeExtension flags a false-positive warning in newer IDEs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-junit5.