(for future reference)
To use Kotlin and Spek + JUnit5 in Android Studio, you need the following:
In the project build.gradle project you need:
buildscript { ext.kotlin_version = '1.2.10' ext.JUnit5_version = '1.0.30' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "de.mannodermaus.gradle.plugins:android-junit5:$JUnit5_version" } }
In the module build.gradle module you need:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: "de.mannodermaus.android-junit5" android { ... sourceSets { test.java.srcDirs += 'src/test/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' } } project.ext { spekVersion = "1.1.5" } dependencies { ... // // TESTS testImplementation("org.jetbrains.spek:spek-api:$spekVersion") { exclude group: "org.jetbrains.kotlin" } testImplementation("org.jetbrains.spek:spek-junit-platform-engine:$spekVersion") { exclude group: "org.junit.platform" exclude group: "org.jetbrains.kotlin" } testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testImplementation junit5.unitTests() // see https://github.com/mannodermaus/android-junit5
Simple Spek Test
class ExampleSpekTest : Spek({ val x = 2 val y = 3 given("x = $x and y = $y") { val sum = x + y it("should be that x + y = 5") { Assert.assertEquals(5, sum) } it("should be that x - y = -1") { val subtract = x - y Assert.assertEquals(-1, subtract) } } })
Cm
- official documentation http://spekframework.org/
- the official plugin for launching specifications from the IDE https://github.com/raniejade/spek-idea-plugin
- Tests using the Spek Framework - BDD Style vs JUnit Style https://www.youtube.com/watch?v=asDZ_7ZUiX4
- Simple configuration of Android Spek and JUnit5 https://gist.github.com/Mugurell/088daf42a4d60240ba6993681e0537a5
source share