raniejade / spek-idea-plugin

MIT License
48 stars 15 forks source link

Failed to discover tests #51

Closed neoneo closed 7 years ago

neoneo commented 7 years ago

Hi,

I keep getting the following error in IDEA:

org.junit.platform.launcher.core.DefaultLauncher handleThrowable
WARNING: TestEngine with ID 'spek' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.engine.support.descriptor.ClassSource.from(Ljava/lang/Class;)Lorg/junit/platform/engine/support/descriptor/ClassSource;
    at org.jetbrains.spek.engine.SpekTestEngine.resolveSpec(SpekTestEngine.kt:114)
    at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:80)
    at org.jetbrains.spek.engine.SpekTestEngine.discover(SpekTestEngine.kt:50)
    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 org.jetbrains.spek.tooling.runner.junit.JUnitPlatformSpekRunner.run(JUnitPlatformSpekRunner.kt:107)
    at org.jetbrains.spek.tooling.MainKt.main(Main.kt:58)

Running from the command line works fine.

I've found a related issue here: https://github.com/spekframework/spek/issues/256, but none of the tips posted there have helped. Probably because it's an Android Studio issue, while I'm using IntelliJ IDEA for a non-Android project.

build.gradle:

buildscript {
    ext {
        kotlin_version = '1.1.51'
        vertx_version = '3.4.2'
        spek_version = '1.1.5'
        kluent_version = '1.30'
    }

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0"
    }
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.junit.platform.gradle.plugin'

sourceCompatibility = '1.8'

junitPlatform {
    filters {
        engines {
            include 'spek'
        }
    }
}

repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/jetbrains/spek" }
    maven { url "https://dl.bintray.com/markusamshove/maven/" }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    compile "io.vertx:vertx-core:$vertx_version"
    compile "io.vertx:vertx-web:$vertx_version"
    testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    testCompile "org.jetbrains.spek:spek-api:$spek_version"
    testRuntime "org.jetbrains.spek:spek-junit-platform-engine:$spek_version"
    testCompile "org.amshove.kluent:kluent:$kluent_version"
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

How can I get this working? Thanks a lot in advance.

Jeroen

raniejade commented 7 years ago

can you try adding a dependency to org.junit.platform:junit-platform-runner:${junitPlatformVersion}?

neoneo commented 7 years ago

That was it, thanks!

snasirca commented 6 years ago

@raniejade's solution worked for me and just to clarify: this is exactly what I did in my Kotlin DSL Gradle build.gradle.kts:

dependencies {
    // ...
    testCompile("org.junit.platform:junit-platform-runner:1.0.1")
}