1

I want to use kotest ExpectSpec in Android. But I don't know how to setup Junit5 runner.

This is my app-level build.gradle file

...

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

dependencies {
    ...

    testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2"
    testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2"
    testImplementation 'junit:junit:4.13.2'
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.8.2"
    testImplementation 'org.robolectric:robolectric:4.8'
    testImplementation 'androidx.test:core:1.5.0'
    testImplementation 'io.kotest:kotest-runner-junit5:5.6.0'
    testImplementation "io.mockk:mockk:1.13.4"
    testImplementation 'androidx.arch.core:core-testing:2.2.0'
    testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.8.20"

    debugImplementation "androidx.fragment:fragment-testing:1.6.1"
}

This is my Top-level build.gradle

buildscript {
    ext.kotlin_version = '1.7.10'

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "de.mannodermaus.gradle.plugins:android-junit5:1.9.3.0"
    }
}

This is my testing code.

import io.kotest.core.spec.style.ExpectSpec
import io.kotest.matchers.shouldBe

class PlusTest : ExpectSpec({
    context("plus") {
        expect("2 plus 3") {
            val result = 2 + 3
            result shouldBe 5
        }
    }
})

How can I run PlusTest?

Doo Rim
  • 11
  • 1
  • If you're writing an Unit Test, this should be all you need to do to execute it. Do you get any errors when trying to execute for example `gradlew test`? – LeoColman Aug 03 '23 at 22:05
  • No I don't have any errors. But, I want to run this class only. How can I run only this class?! @LeoColman – Doo Rim Aug 04 '23 at 00:30
  • Do you have the kotest plugin installed? https://kotest.io/docs/intellij/intellij-plugin.html – LeoColman Aug 04 '23 at 23:52

0 Answers0