Skip to content

Commit 1b5d654

Browse files
authored
Add: test to verify if coverage is created with clearPackageData=true (#96)
Turns out this test does not succeed, but this seems to be a bug in the Android Tooling and not something this plugin can solve. See: #83
1 parent d36ddb4 commit 1b5d654

File tree

5 files changed

+70
-5
lines changed

5 files changed

+70
-5
lines changed

gradle/libs.versions.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ androidGradlePluginApi = { module = "com.android.tools.build:gradle-api", vers
1414
junit = { module = "junit:junit", version = "4.13.2" }
1515
truth = { module = "com.google.truth:truth", version = "1.1.3" }
1616
supportTestRunner = { module = "androidx.test:runner", version = "1.5.2" }
17+
testOrchestrator = { module = "androidx.test:orchestrator", version = "1.4.2" }
1718
espressoCore = { module = "androidx.test.espresso:espresso-core", version = "3.5.1" }
1819
androidJUnit = { module = "androidx.test.ext:junit", version = "1.1.5" }
1920
commonsCsv = { module = "org.apache.commons:commons-csv", version = "1.10.0" }

plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/IntegrationTest.kt

+16-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class IntegrationTest(
3737
val isGradleManagedDeviceTest =
3838
configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices")?.toBoolean() ?: false
3939
Assume.assumeFalse(System.getenv("GITHUB_ACTIONS") != null && isGradleManagedDeviceTest)
40+
41+
Assume.assumeFalse(configuration.ignore)
4042
}
4143

4244
@Test
@@ -67,6 +69,14 @@ class IntegrationTest(
6769
""
6870
}
6971
)
72+
73+
putValue("defaultConfig.clearPackageData", "testInstrumentationRunnerArguments clearPackageData: 'true'".takeIf { configuration.projectConfiguration.clearPackageData })
74+
75+
val testOrchestrator = configuration.projectConfiguration.testOrchestrator
76+
77+
putValue("defaultConfig.testOrchestrator", "testInstrumentationRunnerArguments useTestStorageService: 'true'".takeIf { testOrchestrator })
78+
putValue("testOptions.testOrchestrator", "execution 'ANDROIDX_TEST_ORCHESTRATOR'".takeIf { testOrchestrator })
79+
putValue("dependencies.testOrchestrator", "androidTestUtil libs.testOrchestrator".takeIf { testOrchestrator })
7080
}
7181
File(projectRoot, "app/build.gradle.tmp").inputStream().use {
7282
File(projectRoot, "app/build.gradle").writeText(templateAppBuildGradleFile.process(it, Charsets.UTF_8))
@@ -212,6 +222,7 @@ class IntegrationTest(
212222
}
213223

214224
data class TestConfiguration(
225+
val ignore: Boolean = false,
215226
val projectConfiguration: ProjectConfiguration,
216227
val pluginConfiguration: PluginConfiguration
217228
) {
@@ -225,6 +236,10 @@ class IntegrationTest(
225236
data class Property(val name: String, val value: String)
226237
}
227238

228-
data class ProjectConfiguration(val addGradleManagedDevice: Boolean = true)
239+
data class ProjectConfiguration(
240+
val addGradleManagedDevice: Boolean = true,
241+
val clearPackageData: Boolean = false,
242+
val testOrchestrator: Boolean = false,
243+
)
229244
}
230245
}

plugin/src/test/kotlin/org/neotech/plugin/rootcoverage/util/SimpleTemplate.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import java.nio.charset.Charset
99
*/
1010
internal class SimpleTemplate {
1111

12-
private val map = mutableMapOf<String, String>()
12+
private val map = mutableMapOf<String, String?>()
1313

14-
fun putValue(key: String, value: String) {
14+
fun putValue(key: String, value: String?) {
1515
map[key] = value
1616
}
1717

@@ -43,7 +43,7 @@ internal class SimpleTemplate {
4343
}
4444

4545
// Get the replacement string and indent it
46-
val replacement = mapWithBrackets[indexOf.second]!!.prependWhitespaceIndentExceptFirstLine(indent)
46+
val replacement = mapWithBrackets[indexOf.second] ?: "".prependWhitespaceIndentExceptFirstLine(indent)
4747

4848
adjustedLine.replace(indexOf.first, indexOf.first + indexOf.second.length, replacement)
4949
startIndex += replacement.length

plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ android {
1515
versionCode 1
1616
versionName "1.0"
1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
19+
{{defaultConfig.clearPackageData}}
20+
21+
{{defaultConfig.testOrchestrator}}
1822
}
1923

2024
buildFeatures {
@@ -42,8 +46,9 @@ android {
4246
includeAndroidResources = true
4347
}
4448

45-
{{managedDevices}}
49+
{{testOptions.testOrchestrator}}
4650

51+
{{managedDevices}}
4752
}
4853

4954
kotlinOptions {
@@ -57,5 +62,11 @@ dependencies {
5762
implementation libs.appCompat
5863

5964
testImplementation libs.bundles.androidTest
65+
66+
{{dependencies.testOrchestrator}}
67+
68+
androidTestUtil "androidx.test.services:test-services:1.4.2"
69+
6070
androidTestImplementation libs.bundles.androidInstrumentedTest
71+
6172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This test was added in reaction to:
2+
# https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin/issues/83
3+
#
4+
# Currently this test case fails, but probably not because of this plugin as it seems to be
5+
# an Android tooling issue:
6+
# - https://issuetracker.google.com/issues/126258801
7+
# - https://issuetracker.google.com/issues/123987001
8+
#
9+
# For now this test configuration is ignored (until Google fixes this)
10+
ignore: true
11+
projectConfiguration:
12+
addGradleManagedDevice: false
13+
clearPackageData: true
14+
testOrchestrator: true
15+
pluginConfiguration:
16+
properties:
17+
- name: generateHtml
18+
value: true
19+
- name: generateXml
20+
value: false
21+
- name: generateCsv
22+
value: true
23+
24+
- name: buildVariant
25+
value: debug
26+
27+
- name: executeUnitTests
28+
value: true
29+
- name: includeUnitTestResults
30+
value: true
31+
32+
- name: executeAndroidTests
33+
value: false
34+
- name: includeAndroidTestResults
35+
value: true
36+
37+
- name: includeNoLocationClasses
38+
value: true

0 commit comments

Comments
 (0)