Skip to content

Commit c048a60

Browse files
author
Marcel Schnelle
authored
Update to JUnit 5.4.1 & Introduce Firebase Test Lab (#156)
1 parent 3226b13 commit c048a60

File tree

9 files changed

+131
-33
lines changed

9 files changed

+131
-33
lines changed

.circleci/config.yml

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ defaults: &defaults
77
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError"'
88

99
cache_key: &cache_key
10-
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/android-junit5-tests/build.gradle.kts" }}-{{ checksum "instrumentation/api/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
10+
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/android-junit5-tests/build.gradle.kts" }}-{{ checksum "instrumentation/api/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "buildSrc/src/main/kotlin/Artifacts.kt" }}-{{ checksum "buildSrc/src/main/kotlin/Libs.kt" }}-{{ checksum "buildSrc/src/main/kotlin/Versions.kt" }}
1111

1212
version: 2
1313
jobs:
14-
build:
14+
build_plugin:
1515
<<: *defaults
1616
steps:
1717
- checkout
@@ -25,39 +25,84 @@ jobs:
2525
name: (Plugin) Test
2626
command: cd plugin && ./gradlew :android-junit5-tests:check --stacktrace --no-daemon
2727

28+
- persist_to_workspace:
29+
root: ~/root
30+
paths:
31+
- project
32+
- store_artifacts:
33+
path: plugin/android-junit5-tests/build/reports/tests/test
34+
destination: plugin
35+
36+
build_instrumentation:
37+
<<: *defaults
38+
steps:
39+
- checkout
40+
- restore_cache:
41+
<<: *cache_key
2842
- run:
2943
name: (Instrumentation) Download Dependencies
3044
command: cd instrumentation && ./gradlew androidDependencies --no-daemon
45+
- save_cache:
46+
<<: *cache_key
47+
paths:
48+
- ~/.gradle/caches
49+
- ~/.gradle/wrapper
3150
- run:
3251
name: (Instrumentation) Build
33-
command: cd instrumentation && ./gradlew :api:assemble :core:assemble :runner:assemble --stacktrace --no-daemon
52+
command: |
53+
cd instrumentation
54+
./gradlew :api:assembleDebug \
55+
:core:assembleDebug :core:assembleDebugAndroidTest \
56+
:runner:assembleDebug \
57+
:sample:assembleDebug --stacktrace --no-daemon
3458
- run:
3559
name: (Instrumentation) Test
3660
command: cd instrumentation && ./gradlew :api:check :core:check :runner:check --stacktrace --no-daemon
61+
- run:
62+
name: Store Google Service Account
63+
command: echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
64+
- run:
65+
name: Authorize gcloud and set config defaults
66+
command: |
67+
sudo gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
68+
sudo gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
69+
- run:
70+
name: Test with Firebase Test Lab
71+
command: >
72+
sudo gcloud firebase test android run \
73+
--type instrumentation \
74+
--app instrumentation/sample/build/outputs/apk/debug/sample-debug.apk \
75+
--test instrumentation/core/build/outputs/apk/androidTest/debug/android-test-core-debug-androidTest.apk \
76+
--environment-variables runnerBuilder=de.mannodermaus.junit5.AndroidJUnit5Builder \
77+
--test-runner-class androidx.test.runner.AndroidJUnitRunner \
78+
--device model=sailfish,version=28,locale=en_US,orientation=portrait \
79+
--results-bucket cloud-test-${GOOGLE_PROJECT_ID} \
80+
--timeout 15m
81+
- run:
82+
name: Install gsutil dependency and copy test results data
83+
command: |
84+
sudo pip install -U crcmod
85+
mkdir test-lab-results
86+
sudo gsutil -m cp -r -U `sudo gsutil ls gs://cloud-test-${GOOGLE_PROJECT_ID} | tail -1` test-lab-results/ | true
3787
38-
- save_cache:
39-
<<: *cache_key
40-
paths:
41-
- ~/.gradle/caches
42-
- ~/.gradle/wrapper
4388
- persist_to_workspace:
4489
root: ~/root
4590
paths:
4691
- project
47-
- store_artifacts:
48-
path: plugin/android-junit5-tests/build/reports/tests/test
49-
destination: plugin
5092
- store_artifacts:
5193
path: instrumentation/api/build/reports
5294
destination: instrumentation-api
5395
- store_artifacts:
5496
path: instrumentation/core/build/reports
5597
destination: instrumentation-core
98+
- store_artifacts:
99+
path: test-lab-results
100+
destination: instrumentation-core/test-lab-results
56101
- store_artifacts:
57102
path: instrumentation/runner/build/reports
58103
destination: instrumentation-runner
59104

60-
deploy_snapshots:
105+
deploy_plugin_snapshots:
61106
<<: *defaults
62107
steps:
63108
- attach_workspace:
@@ -67,6 +112,14 @@ jobs:
67112
- run:
68113
name: (Plugin) Deploy SNAPSHOTs
69114
command: cd plugin && ./gradlew publishLibraryPublicationToSnapshotRepository --stacktrace --no-daemon
115+
116+
deploy_instrumentation_snapshots:
117+
<<: *defaults
118+
steps:
119+
- attach_workspace:
120+
at: ~/root
121+
- restore_cache:
122+
<<: *cache_key
70123
- run:
71124
name: (Instrumentation) Deploy SNAPSHOTs
72125
command: cd instrumentation && ./gradlew publishLibraryPublicationToSnapshotRepository --stacktrace --no-daemon
@@ -98,24 +151,31 @@ workflows:
98151

99152
build_deploy:
100153
jobs:
101-
- build
102-
- deploy_snapshots:
154+
- build_plugin
155+
- build_instrumentation
156+
- deploy_plugin_snapshots:
157+
requires:
158+
- build_plugin
159+
filters:
160+
branches:
161+
only: master
162+
- deploy_instrumentation_snapshots:
103163
requires:
104-
- build
164+
- build_instrumentation
105165
filters:
106166
branches:
107167
only: master
108168
- deploy_plugin_release:
109169
requires:
110-
- build
170+
- build_plugin
111171
filters:
112172
branches:
113173
only: master
114174
tags:
115175
only: plugin-*
116176
- deploy_instrumentation_release:
117177
requires:
118-
- build
178+
- build_instrumentation
119179
filters:
120180
branches:
121181
only: master

buildSrc/src/main/kotlin/Artifacts.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object Artifacts {
3535
platform = Java,
3636
groupId = "de.mannodermaus.gradle.plugins",
3737
artifactId = "android-junit5",
38-
currentVersion = "1.4.0.1-SNAPSHOT",
38+
currentVersion = "1.4.1.0-SNAPSHOT",
3939
latestStableVersion = "1.4.0.0",
4040
license = license,
4141
description = "Unit Testing with JUnit 5 for Android."

buildSrc/src/main/kotlin/Tasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import java.io.File
1616
open class WriteClasspathResource : DefaultTask() {
1717

1818
@InputFiles
19-
lateinit var inputFiles: FileCollection
19+
lateinit var inputFiles: Iterable<File>
2020
@OutputDirectory
2121
lateinit var outputDir: File
2222
lateinit var resourceFileName: String

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ object Versions {
5858

5959
const val junit_pioneer: String = "0.2.2" // available: "0.3.0"
6060

61-
const val org_junit_jupiter: String = "5.4.0"
61+
const val org_junit_jupiter: String = "5.4.1"
6262

63-
const val org_junit_platform: String = "1.4.0"
63+
const val org_junit_platform: String = "1.4.1"
6464

65-
const val junit_vintage_engine: String = "5.4.0"
65+
const val junit_vintage_engine: String = "5.4.1"
6666

6767
const val mockito_core: String = "2.19.0" // available: "2.23.4"
6868

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.mannodermaus.junit5
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
6+
/**
7+
* This JUnit 4 test class is here to validate
8+
* that older device, which ignore JUnit 5 tests,
9+
* still execute older ones.
10+
*/
11+
class BaselineJUnit4Test {
12+
13+
@Test
14+
fun run() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

plugin/.idea/runConfigurations/Plugin__Run_Unit_Tests__All_.xml

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/.idea/runConfigurations/Plugin__Run_Unit_Tests__No_Functional_.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/android-junit5-tests/build.gradle.kts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ dependencies {
8888
testImplementation(project(":android-junit5"))
8989
testImplementation(gradleTestKit())
9090
testImplementation(Libs.kotlin_gradle_plugin)
91-
testImplementation(Libs.com_android_tools_build_gradle)
9291
testImplementation(Libs.commons_io)
9392
testImplementation(Libs.commons_lang)
9493
testImplementation(Libs.junit)
@@ -99,6 +98,8 @@ dependencies {
9998
testImplementation(Libs.assertj_core)
10099
testImplementation(Libs.mockito_core)
101100

101+
testCompileOnly(Libs.com_android_tools_build_gradle)
102+
102103
testRuntimeOnly(Libs.junit_jupiter_engine)
103104
testRuntimeOnly(Libs.junit_vintage_engine)
104105
testRuntimeOnly(Libs.spek_junit_platform_engine)
@@ -128,7 +129,25 @@ dependencies {
128129

129130
// Resource Writers
130131
tasks.create("writePluginClasspath", WriteClasspathResource::class) {
131-
inputFiles = sourceSets["test"].runtimeClasspath
132+
// Exclude "current AGP" dependencies from being packages;
133+
// those are added again explicitly, through the functionalTestAgpXXX configurations.
134+
val targetVersions = listOf(
135+
// Android Gradle Plugin itself
136+
Versions.com_android_tools_build_gradle,
137+
// Dependent artifacts in the Android space which use major version 26, for some reason
138+
// (e.g. com.android.tools.analytics).
139+
// TODO This will need updating when AGP 4 comes out at some point
140+
Versions.com_android_tools_build_gradle.replaceFirst("3.", "26.")
141+
)
142+
val targetGroups = listOf(
143+
"com.android",
144+
"androidx"
145+
)
146+
147+
inputFiles = sourceSets["test"].runtimeClasspath.filterNot { file ->
148+
// If a dependency file matches any of the blacklisted artifacts, filter it out
149+
targetVersions.any { it in file.absolutePath } && targetGroups.any { it in file.absolutePath }
150+
}
132151
outputDir = File("$buildDir/resources/test")
133152
resourceFileName = "plugin-classpath.txt"
134153
}

plugin/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/FunctionalTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import org.junit.jupiter.api.DynamicTest.dynamicTest
1212
import org.junit.jupiter.api.Test
1313
import org.junit.jupiter.api.TestFactory
1414
import org.junit.jupiter.api.extension.ExtendWith
15-
import org.junitpioneer.jupiter.TempDirectory
16-
import org.junitpioneer.jupiter.TempDirectory.TempDir
15+
import org.junit.jupiter.api.io.TempDir
1716
import java.io.File
1817
import java.nio.file.Files
1918
import java.nio.file.Path
@@ -28,7 +27,6 @@ import java.nio.file.Paths
2827
data class FunctionalTest(val name: String, val config: String, val gradleVersion: String)
2928

3029
@OnlyOnLocalMachine
31-
@ExtendWith(TempDirectory::class)
3230
class FunctionalTests {
3331

3432
companion object {
@@ -39,7 +37,7 @@ class FunctionalTests {
3937

4038
FunctionalTest(name = "3.3.x", config = "functionalTestAgp33X", gradleVersion = "5.0"),
4139

42-
FunctionalTest(name = "3.4.x", config = "functionalTestAgp34X", gradleVersion = "5.1-milestone-1")
40+
FunctionalTest(name = "3.4.x", config = "functionalTestAgp34X", gradleVersion = "5.2.1")
4341
)
4442
private val SUPPORTED_LANGUAGES = FileLanguage2.values().toList()
4543

@@ -48,6 +46,7 @@ class FunctionalTests {
4846

4947
private lateinit var testProjectDir: File
5048
private lateinit var buildFile: File
49+
// Main classpath for plugins
5150
private lateinit var pluginFiles: List<File>
5251

5352
// Classpath of the main "functionalTest" configuration
@@ -94,6 +93,7 @@ class FunctionalTests {
9493
buildscript {
9594
dependencies {
9695
classpath files(${pluginFiles.splitClasspath()})
96+
classpath files(${functionalTestSpecialFiles.splitClasspath()})
9797
}
9898
}
9999
""")

0 commit comments

Comments
 (0)