Spek: Unable to run with JUnit Platform 1.0.0-M4

Created on 31 Mar 2017  路  11Comments  路  Source: spekframework/spek

I'm trying to run a simple test using ./gradlew junitPlatformTest but I'm getting the following exception:

Exception in thread "main" java.lang.AbstractMethodError: Method org/jetbrains/spek/engine/Scope$Group.getType()Lorg/junit/platform/engine/TestDescriptor$Type; is abstract
        at org.jetbrains.spek.engine.Scope$Group.getType(Scope.kt)
        at org.junit.platform.launcher.TestIdentifier.from(TestIdentifier.java:60)
        at org.junit.platform.launcher.TestPlan.lambda$from$0(TestPlan.java:78)
        at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:245)
        at org.junit.platform.engine.TestDescriptor.lambda$accept$0(TestDescriptor.java:247)
        at java.lang.Iterable.forEach(Iterable.java:75)
        at org.junit.platform.engine.TestDescriptor.accept(TestDescriptor.java:247)
        at org.junit.platform.launcher.TestPlan.lambda$from$1(TestPlan.java:79)
        at java.util.LinkedHashMap$LinkedValues.forEach(LinkedHashMap.java:608)
        at org.junit.platform.launcher.TestPlan.from(TestPlan.java:79)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:130)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:87)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:65)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57)
        at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
        at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57)
        at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:79)
        at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:69)
        at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:41)
:phoenix-common:junitPlatformTest FAILED

Any idea on how to fix this?

Test file

package com.researchnow.phoenix.common

import com.google.common.util.concurrent.Futures
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on

/**
 * Created by vreventos on 3/30/17.
 */
object FutureUtilSpec : Spek({

    describe("FutureUtils toCompletableFuture") {
        on("a cancelled future") {
            it("should returned cancelled") {
                val f = Futures.immediateCancelledFuture<Any>().toCompletableFuture()
                assert(f.isCompletedExceptionally)
            }
        }
    }

})

build.gradle

buildscript {
    ext {
        grpcVersion = '1.2.0'
        braveVersion = '3.16.0'
        brawndoVersion = '5.3.433'
        kotlinVersion = '1.1.1'
    }
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

apply plugin: 'idea'

repositories {
    jcenter()
    maven { url "http://dl.bintray.com/jetbrains/spek" }
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'maven-publish'

    group = 'com.researchnow'

    task wrapper(type: Wrapper) {
        gradleVersion = '3.3'
    }
}

subprojects {
    repositories {
        maven { url "http://dl.bintray.com/jetbrains/spek" }
        jcenter()
    }

    buildscript {
        dependencies {
            classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        }
    }

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'kotlin'
    apply plugin: "org.junit.platform.gradle.plugin"

    sourceCompatibility = 8
    targetCompatibility = 8

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

    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
        testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
        testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
        testCompile "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
        testCompile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
        testCompile ('org.jetbrains.spek:spek-api:1.1.0') {
            exclude group: 'org.jetbrains.kotlin'
        }
        testCompile ('org.jetbrains.spek:spek-junit-platform-engine:1.1.0') {
            exclude group: 'org.junit.platform'
            exclude group: 'org.jetbrains.kotlin'
        }
    }

}

Most helpful comment

@eekboom as a workaround please add org.junit.platform:junit-platform-launcher:1.0.0-M4 in the test classpath. The plugin bundles 1.0.0-M3 and only uses that if you don't have the junit-platform-launcher in your test classpath.

All 11 comments

I also get this error when attempting to use Kotlin 1.0.6.

It appears somehow junit5's console is getting brought into the mix and it is attempting to use platform components from junit5. Adding this to my build.gradle's dependencies solved the problem for me:

dependencies {
   testCompile 'org.junit.platform:junit-platform-console:1.0.0-M3'
}

Also to clarify, I followed the instructions from the docs regarding using JUnit 4. After adding the junit-platform-console dependency, I no longer needed the @RunWith annotations on the specs.

I have observed this as well and it seems like the Milestone 4 release of JUnit is automatically getting used when running tests (even though M3 is configured) and presumably an API change broke Spek.

It seems like the JUnit Gradle plugin usually adds the engine dependencies itself when running the tests, however it appears to be using the newest version instead of the version of the plugin.

Can confirm that adding the junit-platform-console dependency to the classpath fixes this issue.

What makes this slightly annoying is that this can break existing builds that worked fine before...

You can configure w/c version to use via the junitPlatform block. I haven't tried using 1.0.0-M4 with Spek, will have to investigate but I'm guessing there are some breaking changes to the API.

junitPlatform {
    platformVersion '1.0.0-M3'
}

@Tobi29 your issue could be related to https://github.com/junit-team/junit5/issues/576 , where the default dependency brought in by the extension is dynamic so retrieves the "highest" one.

It was fixed in M4 so that it does not use a dynamic version string by default.

@raniejade That fixes the issue.

Should this be added to the official documentation?

Using M3 I encountered NPEs that break surefire/failsafe. Switching to M4 gives the more revealing stacktrace posted by @vjames19. I'd like to stick to M4, if possible. If it would help, I can do some investigation and see if a simple PR would fix.

Re-titled to point out the main culprit.

1.1.1 with this fix is now available.

Aaaarg.
With 1.1.1 I can run "gradle test" from the gradle toolwindow and it works. (At least mostly: The "run" toolwindow in IDEA says "Test events were not received", but the console shows the test statistics).

However I can no longer run a single test in IDEA by using the left gutter icon (from the Spek) plugin. Then I get "java.lang.AbstractMethodError: Method org/jetbrains/spek/engine/Scope$Group.isTest()Z is abstract".

With 1.1.0 the former fails with the error described in this issue, but running a single test via the Spek plugin works fine.

Can I have both, please ;-)

@eekboom as a workaround please add org.junit.platform:junit-platform-launcher:1.0.0-M4 in the test classpath. The plugin bundles 1.0.0-M3 and only uses that if you don't have the junit-platform-launcher in your test classpath.

Was this page helpful?
0 / 5 - 0 ratings