Search code examples
androidkotest

Using AbstractProjectConfig in Android project


I am trying to set a global project configuration for Kotest. I have followed the instructions at https://kotest.io/project_config/

However, I have a number of unresolved items in the below:

package io.kotest.provided

import io.kotest.core.config.AbstractProjectConfig

object ProjectConfig : AbstractProjectConfig() {
    override val assertionMode = AssertionMode.Error
}

Where, in the import statement, core is unresolved.

AbstractProjectConfig is unresolved.

AssertionMode is unresolved.

So then of course, assertionMode "overrides nothing" as well

In my app-level build.gradle, I have

dependencies {

[...]

    testImplementation 'io.kotest:kotest-runner-junit5:4.3.1' // for kotest framework
    testImplementation 'io.kotest:kotest-assertions-core:4.3.1' // for kotest core jvm assertions
    testImplementation 'io.kotest:kotest-property:4.3.1' // for kotest property test
}

android.testOptions {
    unitTests.all {
        useJUnitPlatform()
    }
}

Is it possible to use AbstractProjectConfig within an Android project? If so, where have I gone wrong please?


Solution

  • So it seems that the kotest documentation is slightly misleading (I have filed an issue: https://github.com/kotest/kotest/issues/1866). I have found that the dependencies needed in my app-level build.gradle are of the form:

    dependencies {
        testImplementation("io.kotest:kotest-runner-junit5-jvm:<version>")
        androidTestImplementation("io.kotest:kotest-runner-junit5-jvm:<version>") {
            exclude(module: "objenesis")
        }
        androidTestImplementation("io.kotest:kotest-assertions-core-jvm:<version>")
    

    As given in the sample app at https://github.com/kotest/kotest-android-samples/blob/master/app/build.gradle

    Referring to those shown at https://kotest.io/quick_start/#gradle there are a few key differences:

    dependencies {
        testImplementation 'io.kotest:kotest-runner-junit5:<version>' // for kotest framework
        testImplementation 'io.kotest:kotest-assertions-core:<version>' // for kotest core jvm assertions
        testImplementation 'io.kotest:kotest-property:<version>' // for kotest property test
    }
    

    Note that the sample-app dependencies work, those in the docs do not.

    i.e. the suffix -jvm is required, and in some cases androidTestImplementation is required rather than testImplementation. I'm new to testing and Android and this wasn't obvious to me, so apologies if this is something that someone more experienced would have worked out at a glance!