Skip to content

Commit

Permalink
Add Gradle property for disabling combined screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Oct 2, 2023
1 parent 1627262 commit e5f041a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
}
}

Expand All @@ -59,11 +77,4 @@ class AndroidLibraryRoborazziConventionPlugin : ConventionPlugin({
},
)
}

tasks.withType<Test>().configureEach {
// Increase memory and parallelize Roborazzi tests
maxHeapSize = "2g"
maxParallelForks = if (System.getenv("CI") == "true") 1 else 4
forkEvery = 12
}
})
28 changes: 28 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e5f041a

Please sign in to comment.