Code Monkey home page Code Monkey logo

Comments (11)

ivnsch avatar ivnsch commented on May 23, 2024 1

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.

mannodermaus avatar mannodermaus commented on May 23, 2024 1

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.

mannodermaus avatar mannodermaus commented on May 23, 2024

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.

ivnsch avatar ivnsch commented on May 23, 2024

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.

ivnsch avatar ivnsch commented on May 23, 2024

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.

mannodermaus avatar mannodermaus commented on May 23, 2024

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.

ivnsch avatar ivnsch commented on May 23, 2024

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.

ivnsch avatar ivnsch commented on May 23, 2024

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.

mannodermaus avatar mannodermaus commented on May 23, 2024

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.

ivnsch avatar ivnsch commented on May 23, 2024

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.

mannodermaus avatar mannodermaus commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.