Comments (11)
After reading this, I added this to my dependencies:
compile "org.junit.platform:junit-platform-launcher:1.0.0-M4"
But now I get:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.engine.discovery.DiscoverySelectors.selectNames(Ljava/util/Collection;)Ljava/util/List;
at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:75)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
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.AppMain.main(AppMain.java:147)
According to junit-team/junit5#586 this is related with using an incompatible launcher version...? But it passed Gradle check at least, I tried first with M3 and Gradle didn't let me.
from android-junit5.
Okay, AS 2.3.3 is most likely the culprit here. The blog post you linked to at the top of this issue described how IJ 2016.x is compiled against an older milestone of JUnit 5. I'm pretty certain that this affects AS 2.3 as well. I don't know the version of IntelliJ it's built against, but I'm fairly certain that it's not a 2017 build.
So for the time being, I'm afraid you either need to update your AS to a more recent version, or wait until the next stable build & use the Gradle task for unit tests until then...
from android-junit5.
I'm assuming you're using version 1.0.0-M4-rev3
of the plugin? How are you defining the dependencies in your build.gradle
? You want to make sure to use the test
configurations for them, e.g. testCompile
instead of compile
.
from android-junit5.
Thanks for the quick answer! Yes, I am. This is the top level build file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.0-M4-rev3"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And the module build file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: "com.android.application"
apply plugin: "de.mannodermaus.android-junit5"
repositories {
mavenCentral()
// maven { url "http://dl.bintray.com/jetbrains/spek" }
}
configurations {
ktlint
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xxx.xxxx.xxxx"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1' // conductor
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'io.reactivex.rxjava2:rxkotlin:2.0.3'
compile 'com.yheriatovych:reductor:0.13.2'
apt 'com.yheriatovych:reductor-processor:0.13.2'
ktlint 'com.github.shyiko:ktlint:0.8.1'
compile 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0'
// specification test framework - http://spekframework.org/
// testCompile 'org.jetbrains.spek:spek-api:1.1.2'
// testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
// compile "org.junit.platform:junit-platform-launcher:1.0.0-M4"
testCompile junitJupiter()
testCompile junitParams() // "parameterized tests"
}
task ktlint(type: JavaExec) {
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt"
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec) {
main = "com.github.shyiko.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}
junitPlatform {
// The JUnit Jupiter dependency version to use; "5.0.0-M4" by default
jupiterVersion "5.0.0-M4"
// The JUnit Vintage Engine dependency version to use; "4.12.0-M4" by default
vintageVersion "4.12.0-M4"
}
//junitPlatform {
// filters {
// engines {
// include 'spek'
// }
// }
//}
from android-junit5.
I noticed now that compile "org.junit.platform:junit-platform-launcher:1.0.0-M4"
doesn't use testCompile
- tried setting it to it but get the same error java.lang.NoSuchMethodError: org.junit.platform.engine.discovery.DiscoverySelectors.selectNames
from android-junit5.
It's odd how the junitJupiter()
dependency clause doesn't seem to configure the transitive dependencies correctly. Could you show your output of ./gradlew dependencies --configuration testCompile -p <app>
, where <app>
is the name of your module? Also, you can try explicitly adding the launcher dependency again, but using testCompile
instead of compile
.
from android-junit5.
Setting launcher dependency to testCompile
is what I just did (see my previous comment) and it didn't change anything to using just compile
- still get missing selectNames
method error.
Output of dependencies:
:app:dependencies
Project :app
testCompile - Classpath for compiling the test sources.
+--- junit:junit:4.12
| --- org.hamcrest:hamcrest-core:1.3
+--- org.junit.platform:junit-platform-launcher:1.0.0-M4
| --- org.junit.platform:junit-platform-engine:1.0.0-M4
| +--- org.junit.platform:junit-platform-commons:1.0.0-M4
| --- org.opentest4j:opentest4j:1.0.0-M2
+--- org.junit.jupiter:junit-jupiter-api:5.0.0-M4
| +--- org.opentest4j:opentest4j:1.0.0-M2
| --- org.junit.platform:junit-platform-commons:1.0.0-M4
+--- org.junit.platform:junit-platform-engine:1.0.0-M4 ()
--- org.junit.jupiter:junit-jupiter-params:5.0.0-M4
--- org.junit.jupiter:junit-jupiter-api:5.0.0-M4 ()(*) - dependencies omitted (listed previously)
BUILD SUCCESSFUL
Total time: 11.489 secs
from android-junit5.
Note: In the previous output launcher was uncommented. This is the output commented:
:app:dependencies
Project :app
testCompile - Classpath for compiling the test sources.
+--- junit:junit:4.12
| --- org.hamcrest:hamcrest-core:1.3
+--- org.junit.jupiter:junit-jupiter-api:5.0.0-M4
| +--- org.opentest4j:opentest4j:1.0.0-M2
| --- org.junit.platform:junit-platform-commons:1.0.0-M4
+--- org.junit.platform:junit-platform-engine:1.0.0-M4
| +--- org.junit.platform:junit-platform-commons:1.0.0-M4
| --- org.opentest4j:opentest4j:1.0.0-M2
--- org.junit.jupiter:junit-jupiter-params:5.0.0-M4
--- org.junit.jupiter:junit-jupiter-api:5.0.0-M4 (*)(*) - dependencies omitted (listed previously)
BUILD SUCCESSFUL
Total time: 2.128 secs
from android-junit5.
I overlooked your follow-up comment regarding testCompile
on the Launcher dependency, sorry about that. The dependency graph looks OK to me - do you see the test failures when running from the IDE? Do they work when running ./gradlew junitPlatformTestDebug/Release
? What version of AS/IJ are you using?
from android-junit5.
Hmm from the terminal it works:
:app:junitPlatformTestDebug
Download https://jcenter.bintray.com/org/junit/jupiter/junit-jupiter-engine/5.0.0-M4/junit-jupiter-engine-5.0.0-M4.pom
Download https://jcenter.bintray.com/org/junit/vintage/junit-vintage-engine/4.12.0-M4/junit-vintage-engine-4.12.0-M4.pom
Download https://jcenter.bintray.com/org/junit/jupiter/junit-jupiter-engine/5.0.0-M4/junit-jupiter-engine-5.0.0-M4.jar
Download https://jcenter.bintray.com/org/junit/vintage/junit-vintage-engine/4.12.0-M4/junit-vintage-engine-4.12.0-M4.jar
╷
├─ JUnit Jupiter ✔app:junitPlatformTestDebug
└─ JUnit Vintage ✔
└─ de.sevenmind.android.ExampleUnitTest ✔
└─ addition_isCorrect ✔Test run finished after 10077 ms
[ 3 containers found ]
[ 0 containers skipped ]
[ 3 containers started ]
[ 0 containers aborted ]
[ 3 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
BUILD SUCCESSFUL
Using AS, directly after this, I still get the missing selectNames
exception...
The terminal test works also without adding launcher explicitly to the dependencies.
I'm using the latest stable version of AS, 2.3.3...
from android-junit5.
Quick update on this: Please try the newly released version 1.0.0-M5
again with your setup. Following the official recommendation from the JUnit 5 User Guide, the latest version of the plugin now attempts to fill in all the dependencies itself, overriding the bundled package in AS. This kind of pollutes the dependency graph, but it has shown excellent results in my installations of AS 2.3 & 3.0 Canary! I hope this will help you as well.
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.