Skip to content

Commit 98d95e8

Browse files
author
Marcel Schnelle
authored
Convert most unit tests to Spek & more work on 1.0.31 (#58)
* Pull in Jupiter for android-junit5-test module * Remove deprecated dependency handlers * Pull in Spek & migrate tests over, also remove deprecated APIs * Convert CallableGroovyTests to JUnit 5 & migrate remainder to AGP 3 syntax * Fix task execution order with ClasspathWrite tasks & junitPlatformTest * Use android-junit5 plugin to drive instrumentation-runner tests
1 parent f10c207 commit 98d95e8

File tree

19 files changed

+1209
-1541
lines changed

19 files changed

+1209
-1541
lines changed

android-junit5-tests/build.gradle

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
import de.mannodermaus.gradle.plugins.junit5.WriteClasspathResource
22
import org.apache.tools.ant.filters.ReplaceTokens
3+
import org.junit.platform.console.options.Details
34

45
apply plugin: "groovy"
56
apply plugin: "java-gradle-plugin"
67
apply plugin: "java-library"
78
apply plugin: "idea"
89
apply plugin: "jacoco"
910
apply plugin: "kotlin"
11+
apply plugin: "org.junit.platform.gradle.plugin"
12+
13+
// ------------------------------------------------------------------------------------------------
14+
// Compilation Tweaks
15+
//
16+
// The plugin currently consists of a codebase wherein Groovy & Kotlin coexist.
17+
// Therefore, the compilation chain has to be well-defined to allow Kotlin
18+
// to call into Groovy code.
19+
//
20+
// The other way around ("call Kotlin from Groovy") is prohibited explicitly.
21+
// ------------------------------------------------------------------------------------------------
22+
compileTestGroovy.dependsOn = compileTestGroovy.taskDependencies.mutableValues - "compileTestJava"
23+
compileTestKotlin.dependsOn compileTestGroovy
24+
compileTestKotlin.classpath += files(compileTestGroovy.destinationDir)
25+
testClasses.dependsOn compileTestKotlin
1026

1127
// Add custom dependency configurations
1228
configurations {
@@ -30,30 +46,39 @@ processTestResources {
3046
}
3147
}
3248

33-
tasks.withType(WriteClasspathResource).all {
34-
processTestResources.finalizedBy it
35-
}
36-
3749
test.testLogging {
3850
events "passed", "skipped", "failed"
3951
exceptionFormat = "full"
4052
}
4153

54+
junitPlatform {
55+
details Details.TREE
56+
enableStandardTestTask true
57+
}
58+
4259
dependencies {
4360
// Test Plugin Dependencies
44-
testCompile project(":android-junit5")
61+
testImplementation project(":android-junit5")
4562

4663
// Utilities for assertions & tests in general
47-
testCompile "commons-io:commons-io:$APACHE_COMMONS_VERSION"
48-
testCompile "commons-lang:commons-lang:$APACHE_COMMONS_VERSION"
64+
testImplementation "commons-io:commons-io:$APACHE_COMMONS_VERSION"
65+
testImplementation "commons-lang:commons-lang:$APACHE_COMMONS_VERSION"
4966

5067
// Dependent Plugins
51-
testCompile "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION"
52-
testCompile "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
68+
testImplementation "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION"
69+
testImplementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
5370

5471
// Test Execution
55-
testCompile "junit:junit:$JUNIT4_VERSION"
56-
testCompile("org.spockframework:spock-core:$SPOCK_VERSION") {
72+
testImplementation "junit:junit:$JUNIT4_VERSION"
73+
testImplementation "org.junit.jupiter:junit-jupiter-api:$JUNIT_JUPITER_VERSION"
74+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$JUNIT_JUPITER_VERSION"
75+
testImplementation "org.jetbrains.spek:spek-api:$SPEK_VERSION"
76+
testRuntimeOnly "org.jetbrains.spek:spek-junit-platform-engine:$SPEK_VERSION"
77+
78+
testImplementation "org.assertj:assertj-core:$ASSERTJ_VERSION"
79+
testImplementation "org.mockito:mockito-core:$MOCKITO_VERSION"
80+
81+
testImplementation("org.spockframework:spock-core:$SPOCK_VERSION") {
5782
exclude group: "org.codehaus.groovy"
5883
}
5984

@@ -77,3 +102,8 @@ task writeFunctionalTestCompileClasspath(type: WriteClasspathResource) {
77102
outputDir = file("$buildDir/resources/test")
78103
resourceFileName = "functional-test-compile-classpath.txt"
79104
}
105+
106+
tasks.withType(WriteClasspathResource).all {
107+
processTestResources.finalizedBy it
108+
junitPlatformTest.mustRunAfter it
109+
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package de.mannodermaus.gradle.plugins.junit5
22

3-
import org.junit.Test
3+
import org.junit.jupiter.api.DisplayName
4+
import org.junit.jupiter.api.Test
45

56
class CallableGroovyTests {
7+
68
@Test
9+
@DisplayName("Callable0 can be invoked")
710
void callable0() {
811
def obj = new Callable0<Integer>({ 2 + 2 })
912
assert obj() == 4
1013
}
1114

1215
@Test
13-
void callable1() {
16+
@DisplayName("Callable1 can be invoked with parameter true")
17+
void callable1True() {
1418
def obj = new Callable1<Boolean, Integer>({ state -> 2 + (state ? 1 : 0) })
1519
assert obj(true) == 3
20+
}
21+
22+
@Test
23+
@DisplayName("Callable1 can be invoked with parameter false")
24+
void callable1False() {
25+
def obj = new Callable1<Boolean, Integer>({ state -> 2 + (state ? 1 : 0) })
1626
assert obj(false) == 2
1727
}
1828
}

android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class FunctionalSpec extends Specification {
337337
lint.enabled false
338338
339339
dependencies {
340-
testCompile files(${
340+
testImplementation files(${
341341
ClasspathSplitter.splitClasspath(testCompileClasspath)
342342
})
343343
}
@@ -361,8 +361,10 @@ class FunctionalSpec extends Specification {
361361
buildFile << """
362362
apply plugin: "de.mannodermaus.android-junit5"
363363
364-
junitPlatform {
365-
details "flat"
364+
android.testOptions {
365+
junitPlatform {
366+
details "flat"
367+
}
366368
}
367369
368370
dependencies {

0 commit comments

Comments
 (0)