Gradle can't find tests

3.1k views Asked by At

I'm using Spek testing framework for my Kotlin project. I am able to run tests through Intellij Idea Spek plugin, but can't run them through gradle (build or test). According to SimpleTest.kt when running from Idea plugin 1 test succeeded and 1 failed, when running via gradle it says that 1 container found with 0 tests. How to set up the launch of tests via gradle?

My gradle and test files:

build.gradle:

buildscript {
    ext.kotlin_version = '1.1.4-2'
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4"
    }
}

apply plugin: "idea"
apply plugin: "java"
apply plugin: "kotlin"
apply plugin: "application"
apply plugin: "org.junit.platform.gradle.plugin"

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

mainClassName = "app.MainKt"

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

dependencies {
    testCompile 'org.jetbrains.kotlin:kotlin-test'
    testCompile 'org.jetbrains.spek:spek-api:1.1.2'
    testCompile 'org.junit.platform:junit-platform-runner:1.0.0-M4'
    testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
}

sourceSets.test.java.srcDirs += 'src/test/kotlin'

src/test/kotlin/SimpleTest.kt:

import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import kotlin.test.assertEquals

class SimpleTest : Spek({
    given("simple test") {
        it("should succeed") {
            assertEquals(1, 1)
        }

        it("shouldn't succeed") {
            assertEquals(0, 1)
        }
    }
})

Gradle test output:

Executing external task 'test'...
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
:generateBuildConfig UP-TO-DATE
:compileBuildConfig UP-TO-DATE
:extractIncludeProto UP-TO-DATE
:extractProto UP-TO-DATE
:generateProto UP-TO-DATE
:compileKotlin UP-TO-DATE
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestKotlin
Using kotlin incremental compilation
:extractIncludeTestProto UP-TO-DATE
:extractTestProto UP-TO-DATE
:generateTestProto NO-SOURCE
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:junitPlatformTest
Test run finished after 5062 ms
[         1 containers found      ]
[         0 containers skipped    ]
[         1 containers started    ]
[         0 containers aborted    ]
[         1 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]
:test
:test SKIPPED
BUILD SUCCESSFUL in 14s
12 actionable tasks: 2 executed, 10 up-to-date
External task execution finished 'test'.
1

There are 1 answers

0
JK Ly On BEST ANSWER

This is due to this issue with compatibility between Spek 1.1.2 and Kotlin 1.1.4 https://github.com/JetBrains/spek/issues/248

This can be resolved by using Spek 1.1.4 and junit-platform 1.0.0-RC2