From e5f041a4b3df86d0aed0ce89be21e8eb69f074fb Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Sun, 1 Oct 2023 17:33:10 -0700 Subject: [PATCH] Add Gradle property for disabling combined screenshot tests --- ...AndroidLibraryRoborazziConventionPlugin.kt | 31 +++++++++++++------ gradle.properties | 28 +++++++++++++++++ .../ui/app/util/BaseRoborazziTest.kt | 2 +- .../ui/wear/util/BaseRoborazziTest.kt | 2 +- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryRoborazziConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryRoborazziConventionPlugin.kt index 781419d692..2f1005d5f9 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryRoborazziConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryRoborazziConventionPlugin.kt @@ -17,13 +17,12 @@ import com.alexvanyo.composelife.buildlogic.ConventionPlugin import com.alexvanyo.composelife.buildlogic.configureTesting import com.android.build.gradle.LibraryExtension +import org.gradle.api.GradleException import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.artifacts.VersionCatalogsExtension -import org.gradle.api.tasks.testing.Test import org.gradle.kotlin.dsl.closureOf import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet @@ -40,7 +39,26 @@ class AndroidLibraryRoborazziConventionPlugin : ConventionPlugin({ libraryExtension.testOptions { unitTests.all { test -> - test.systemProperty("robolectric.graphicsMode", "NATIVE") + test.apply { + systemProperty("robolectric.graphicsMode", "NATIVE") + // Configure parameterization to either be combined, or at the test runner level + systemProperty( + "com.alexvanyo.composelife.combinedScreenshotTests", + when ( + val combinedScreenshotTests = findProperty("com.alexvanyo.composelife.combinedScreenshotTests") + ) { + null, "false" -> "false" + "true" -> "true" + else -> throw GradleException( + "Unexpected value $combinedScreenshotTests for combinedScreenshotTests!", + ) + }, + ) + // Increase memory and parallelize Roborazzi tests + maxHeapSize = "2g" + maxParallelForks = if (System.getenv("CI") == "true") 1 else 4 + forkEvery = 12 + } } } @@ -59,11 +77,4 @@ class AndroidLibraryRoborazziConventionPlugin : ConventionPlugin({ }, ) } - - tasks.withType().configureEach { - // Increase memory and parallelize Roborazzi tests - maxHeapSize = "2g" - maxParallelForks = if (System.getenv("CI") == "true") 1 else 4 - forkEvery = 12 - } }) diff --git a/gradle.properties b/gradle.properties index 131a268dbf..a5f1fce29c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,3 +33,31 @@ android.sdk.channel=3 keeper.disableTestProguardFiles=true roborazzi.test.verify=true + +# Custom project properties +# These values can be overridden for debugging through a task, or in a home gradle.properties file. + +# If "true", parameterization for screenshot tests will be done withing a single run test. +# This is faster, as it requires less teardown/initialization for each test. +# If "false", parameterization will be done by the test runners. +# This results in a single test for each screenshot, to aid in debugging. +# The default value is "true". +com.alexvanyo.composelife.combinedScreenshotTests=true + +# If "true", Android tests will be configured to run twice: once as instrumented tests on emulator +# or a physical device, and once using Robolectric +# If "robolectric", Android tests will be configured to only run using Robolectric. +# If "android", Android tests will be configured to only run using instrumentation on emulator or +# a physical device. +# Running in one configuration makes it easier to debug using Android Studio. +# The default value is "true". +com.alexvanyo.composelife.useSharedTest=true + +# The build type to use for tests. This only applies to application modules, as library modules +# are single-variant. +# The default value is "staging". +com.alexvanyo.composelife.testBuildType=staging + +# If "true", keeper will be used to enable testing with R8 enabled. +# The default value is "true". +com.alexvanyo.composelife.enableKeeper=true diff --git a/ui-app-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/app/util/BaseRoborazziTest.kt b/ui-app-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/app/util/BaseRoborazziTest.kt index 8ed3b09e47..a309b04258 100644 --- a/ui-app-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/app/util/BaseRoborazziTest.kt +++ b/ui-app-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/app/util/BaseRoborazziTest.kt @@ -125,7 +125,7 @@ abstract class BaseRoborazziTest( fun data() = // Check if we want to provide parameterization at the test level // This makes it easier to debug which test is failing, at the cost of speed - if (System.getenv("com.alexvanyo.composelife.screenshots.combined") != "false") { + if (System.getProperty("com.alexvanyo.composelife.combinedScreenshotTests").toBoolean()) { listOf(arrayOf(CombinedRoborazziParameterization)) } else { parameterizations.map { diff --git a/ui-wear-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/wear/util/BaseRoborazziTest.kt b/ui-wear-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/wear/util/BaseRoborazziTest.kt index 717dd96a47..89b54a7128 100644 --- a/ui-wear-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/wear/util/BaseRoborazziTest.kt +++ b/ui-wear-screenshots/src/androidUnitTest/kotlin/com/alexvanyo/composelife/ui/wear/util/BaseRoborazziTest.kt @@ -123,7 +123,7 @@ abstract class BaseRoborazziTest( fun data() = // Check if we want to provide parameterization at the test level // This makes it easier to debug which test is failing, at the cost of speed - if (System.getenv("com.alexvanyo.composelife.screenshots.combined") != "false") { + if (System.getProperty("com.alexvanyo.composelife.combinedScreenshotTests").toBoolean()) { listOf(arrayOf(CombinedRoborazziParameterization)) } else { parameterizations.map {