1

Here is my build.gradle.kts :

import org.jetbrains.kotlin.config.KotlinCompilerVersion

plugins {
    ...
}

android {
    compileSdkVersion(27)

    defaultConfig {
        ...
    }

    buildTypes {
        ...
    }

    sourceSets {
        getByName("main").java.srcDirs("src/main/java", "src/main/kotlin")
        getByName("test").java.srcDirs("src/test/java", "src/test/kotlin")
        getByName("androidTest").java.srcDirs("src/androidTest/java", "src/androidTest/kotlin")
    }

}

tasks.withType<Test> {
    useJUnitPlatform()
}

dependencies {
    implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
    implementation("com.android.support:appcompat-v7:27.1.1")

    ...

    //Test
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.1")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.1.1")

    androidTestImplementation("com.android.support.test:runner:1.0.2")
    androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
    androidTestImplementation("android.arch.core:core-testing:1.1.1")

    testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.10")
    testImplementation("io.mockk:mockk:1.8.7")
}

When building it with ./gradlew build no error occurs but if I use the specified codefrom the doc :

val test by tasks.getting(Test::class) {
    useJUnitPlatform { }
}

I get the following error : Task with name 'test' not found in project ':app'.

My settings.gradle.kts:

include(":app")

Does anyone know what's going on here? It's weird AS can suggest me autocompletion and all but while compiling, I get this unresolved reference.

eskatos
  • 4,174
  • 2
  • 40
  • 42
tufekoi
  • 929
  • 2
  • 14
  • 33

1 Answers1

0

Looks like your issue is with this block,

tasks.withType<Test> {
    useJUnitPlatform()
}

If you're not using test task then you can simply remove that code and that error will be gone !


Edit:

If you want to use test task. try like this in project level build.gradle,

tasks.register("test", Test::class) {
    useJUnitPlatform()
}
Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
  • Don't I need to specify it in order to use classes from Kotlintest? – tufekoi Sep 18 '18 at 09:18
  • I try what you suggested in your edit. I get this error : `Cannot add task 'test' as a task with that name already exists.` – tufekoi Sep 18 '18 at 09:30
  • Have you removed your old one task? – Jeel Vankhede Sep 18 '18 at 09:44
  • Yes I did remove the previous `tasks.withType { useJUnitPlatform() }` – tufekoi Sep 18 '18 at 09:48
  • check if it's already exists elsewhere, according to error stats – Jeel Vankhede Sep 18 '18 at 09:51
  • I did check and it exists nowhere. Ireverted my changes to kotlin DSL now. But I still have the error `Could not find method test() for arguments [build_2masodbfs0dkel3fd2gljcpis$_run_closure3@649f12a] on project ':app' of type org.gradle.api.Project. ` when I add `test {useJUnitPlatform()}` to my app gradle file – tufekoi Sep 26 '18 at 14:37