Skip to content

Commit

Permalink
Add: test to verify if coverage is created with clearPackageData se…
Browse files Browse the repository at this point in the history
…t to `true`

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
  • Loading branch information
Rolf-Smit committed Nov 9, 2023
1 parent d36ddb4 commit 331dc6a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ androidGradlePluginApi = { module = "com.android.tools.build:gradle-api", vers
junit = { module = "junit:junit", version = "4.13.2" }
truth = { module = "com.google.truth:truth", version = "1.1.3" }
supportTestRunner = { module = "androidx.test:runner", version = "1.5.2" }
testOrchestrator = { module = "androidx.test:orchestrator", version = "1.4.2" }
espressoCore = { module = "androidx.test.espresso:espresso-core", version = "3.5.1" }
androidJUnit = { module = "androidx.test.ext:junit", version = "1.1.5" }
commonsCsv = { module = "org.apache.commons:commons-csv", version = "1.10.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class IntegrationTest(
val isGradleManagedDeviceTest =
configuration.pluginConfiguration.getPropertyValue("runOnGradleManagedDevices")?.toBoolean() ?: false
Assume.assumeFalse(System.getenv("GITHUB_ACTIONS") != null && isGradleManagedDeviceTest)

Assume.assumeFalse(configuration.ignore)
}

@Test
Expand Down Expand Up @@ -67,6 +69,10 @@ class IntegrationTest(
""
}
)

putValue("clearPackageData", "testInstrumentationRunnerArguments clearPackageData: 'true'".takeIf { configuration.projectConfiguration.clearPackageData })

putValue("testOptions.execution", "execution 'ANDROIDX_TEST_ORCHESTRATOR'".takeIf { configuration.projectConfiguration.testOrchestrator })
}
File(projectRoot, "app/build.gradle.tmp").inputStream().use {
File(projectRoot, "app/build.gradle").writeText(templateAppBuildGradleFile.process(it, Charsets.UTF_8))
Expand Down Expand Up @@ -212,6 +218,7 @@ class IntegrationTest(
}

data class TestConfiguration(
val ignore: Boolean = false,
val projectConfiguration: ProjectConfiguration,
val pluginConfiguration: PluginConfiguration
) {
Expand All @@ -225,6 +232,10 @@ class IntegrationTest(
data class Property(val name: String, val value: String)
}

data class ProjectConfiguration(val addGradleManagedDevice: Boolean = true)
data class ProjectConfiguration(
val addGradleManagedDevice: Boolean = true,
val clearPackageData: Boolean = false,
val testOrchestrator: Boolean = false,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import java.nio.charset.Charset
*/
internal class SimpleTemplate {

private val map = mutableMapOf<String, String>()
private val map = mutableMapOf<String, String?>()

fun putValue(key: String, value: String) {
fun putValue(key: String, value: String?) {
map[key] = value
}

Expand Down Expand Up @@ -43,7 +43,7 @@ internal class SimpleTemplate {
}

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

adjustedLine.replace(indexOf.first, indexOf.first + indexOf.second.length, replacement)
startIndex += replacement.length
Expand Down
12 changes: 11 additions & 1 deletion plugin/src/test/test-fixtures/multi-module/app/build.gradle.tmp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

{{clearPackageData}}

testInstrumentationRunnerArguments useTestStorageService: "true"
}

buildFeatures {
Expand Down Expand Up @@ -42,8 +46,9 @@ android {
includeAndroidResources = true
}

{{managedDevices}}
{{testOptions.execution}}

{{managedDevices}}
}

kotlinOptions {
Expand All @@ -57,5 +62,10 @@ dependencies {
implementation libs.appCompat

testImplementation libs.bundles.androidTest

androidTestUtil libs.testOrchestrator
androidTestUtil "androidx.test.services:test-services:1.4.2"

androidTestImplementation libs.bundles.androidInstrumentedTest

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This test was added in reaction to:
# https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin/issues/83
#
# The mentioned issue does not seem to be reproducible (anymore?) but at least this test configuration
# avoids potential regression in the future.
#
# Potentially this was not a bug in this plugin, but rather in the Android Gradle Plugin:
# https://issuetracker.google.com/issues/123987001
#
ignore: true
projectConfiguration:
addGradleManagedDevice: false
clearPackageData: true
testOrchestrator: true
pluginConfiguration:
properties:
- name: generateHtml
value: true
- name: generateXml
value: false
- name: generateCsv
value: true

- name: buildVariant
value: debug

- name: executeUnitTests
value: true
- name: includeUnitTestResults
value: true

- name: executeAndroidTests
value: false
- name: includeAndroidTestResults
value: true

- name: includeNoLocationClasses
value: true

0 comments on commit 331dc6a

Please sign in to comment.