-
-
Save electrolobzik/07bca68777f3ba5f736da4f9666f7f60 to your computer and use it in GitHub Desktop.
Spek + JUnit5 config for Android project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.given | |
import org.jetbrains.spek.api.dsl.it | |
import org.junit.Assert | |
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") { | |
(x + y) shouldEqual sum | |
} | |
it("should be that x - y = -1") { | |
val subtract = x - y | |
(x - y) shouldEqual substract | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
apply plugin: "de.mannodermaus.android-junit5" | |
android { | |
compileSdkVersion 26 | |
defaultConfig { | |
applicationId "x.x.x" | |
minSdkVersion 27 | |
targetSdkVersion 26 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
sourceSets { | |
test.java.srcDirs += 'src/test/kotlin' | |
androidTest.java.srcDirs += 'src/androidTest/kotlin' | |
} | |
} | |
project.ext { | |
buildToolsVersion = "26.1.0" | |
constraintLayoutVersion = "1.0.2" | |
spekVersion = "1.1.5" | |
mockitoKotlinVersion = "2.0.0-alpha02" | |
kluentVersion = "1.34" | |
} | |
android.testOptions { | |
junitPlatform { | |
filters { | |
engines { | |
include 'spek' | |
} | |
} | |
} | |
} | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | |
implementation 'com.android.support:appcompat-v7:$buildToolsVersion' | |
implementation 'com.android.support.constraint:constraint-layout:$constraintLayoutVersion' | |
// | |
// 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() | |
testCompileOnly junit5.unitTestsRuntime() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
ext.kotlin_version = '1.2.10' | |
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:1.0.30" | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} | |
} | |
allprojects { | |
repositories { | |
google() | |
jcenter() | |
} | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment