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 10, 2023
1 parent d36ddb4 commit 3c4a69c
Show file tree
Hide file tree
Showing 5 changed files with 70 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,14 @@ class IntegrationTest(
""
}
)

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

val testOrchestrator = configuration.projectConfiguration.testOrchestrator

putValue("defaultConfig.testOrchestrator", "testInstrumentationRunnerArguments useTestStorageService: 'true'".takeIf { testOrchestrator })
putValue("testOptions.testOrchestrator", "execution 'ANDROIDX_TEST_ORCHESTRATOR'".takeIf { testOrchestrator })
putValue("dependencies.testOrchestrator", "androidTestUtil libs.testOrchestrator".takeIf { 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 +222,7 @@ class IntegrationTest(
}

data class TestConfiguration(
val ignore: Boolean = false,
val projectConfiguration: ProjectConfiguration,
val pluginConfiguration: PluginConfiguration
) {
Expand All @@ -225,6 +236,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
13 changes: 12 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"

{{defaultConfig.clearPackageData}}

{{defaultConfig.testOrchestrator}}
}

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

{{managedDevices}}
{{testOptions.testOrchestrator}}

{{managedDevices}}
}

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

testImplementation libs.bundles.androidTest

{{dependencies.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
#
# Currently this test case fails, but probably not because of this plugin as it seems to be
# an Android tooling issue:
# - https://issuetracker.google.com/issues/126258801
# - https://issuetracker.google.com/issues/123987001
#
# For now this test configuration is ignored (until Google fixes this)
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 3c4a69c

Please sign in to comment.