diff --git a/docs/topics/build_setup.md b/docs/topics/build_setup.md index 8a7c431c..ce5767fc 100644 --- a/docs/topics/build_setup.md +++ b/docs/topics/build_setup.md @@ -102,6 +102,13 @@ apply plugin: "io.github.takahirom.roborazzi" +Roborazzi can then be activated in multiple ways: +1. By adding a specific property into the module's `gradle.properties` file, to enable the default mode Roborazzi operates in, e.g. verification. +2. By configuring the `roborazzi.taskType` property in the module's build file or an build convention plugin, again, to enable the default mode Roborazzi operates in. +3. By calling one of the specific tasks created by the Roborazzi plugin; this overrides any previously configured defaults. + +The following table lists the specific configuration options in detail: +
Use Roborazzi task | Use default unit test task | Description | @@ -120,6 +127,9 @@ or `./gradlew testDebugUnitTest -Proborazzi.test.record=true` +or + +`./gradlew testDebugUnitTest` after adding `roborazzi { taskType.set(RoborazziTaskType.Record) }` to your module's Gradle build file or build convention plugin.@@ -143,6 +153,10 @@ or `./gradlew testDebugUnitTest -Proborazzi.test.compare=true` +or + +`./gradlew testDebugUnitTest` after adding `roborazzi { taskType.set(RoborazziTaskType.Compare) }` to your module's Gradle build file or build convention plugin. + | Review changes made to an image. This action will @@ -166,6 +180,10 @@ or `./gradlew testDebugUnitTest -Proborazzi.test.verify=true` +or + +`./gradlew testDebugUnitTest` after adding `roborazzi { taskType.set(RoborazziTaskType.Verify) }` to your module's Gradle build file or build convention plugin. + | Validate changes made to an image. If there is any difference between the current image and the @@ -187,6 +205,10 @@ or `./gradlew testDebugUnitTest -Proborazzi.test.verify=true -Proborazzi.test.record=true` +or + +`./gradlew testDebugUnitTest` after adding `roborazzi { taskType.set(RoborazziTaskType.VerifyAndRecord) }` to your module's Gradle build file or build convention plugin. + |
This task will first verify the images and, if differences are detected, it will record a new
diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt
index c4d9eb64..92b981ea 100644
--- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt
+++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProject.kt
@@ -1,6 +1,7 @@
package io.github.takahirom.roborazzi
import com.github.takahirom.roborazzi.CaptureResults
+import com.github.takahirom.roborazzi.RoborazziTaskType
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.junit.rules.TemporaryFolder
@@ -174,6 +175,7 @@ class RoborazziGradleProject(val testProjectDir: TemporaryFolder) {
private val PATH = "app/build.gradle.kts"
var removeOutputDirBeforeTestTypeTask = false
var customOutputDirPath: String? = null
+ var taskType: RoborazziTaskType? = null
fun addIncludeBuild() {
folder.root.resolve(PATH).delete()
@@ -270,15 +272,22 @@ dependencies {
""".trimIndent()
)
}
+ buildFile.appendText("""
+ roborazzi {
+ """)
if (customOutputDirPath != null) {
- buildFile.appendText(
- """
- roborazzi {
- outputDir.set(file("$customOutputDirPath"))
- }
- """.trimIndent()
- )
+ buildFile.appendText("""
+ outputDir.set(file("$customOutputDirPath"))
+ """.trimIndent())
+ }
+ if (taskType != null) {
+ buildFile.appendText("""
+ taskType.set(com.github.takahirom.roborazzi.RoborazziTaskType.${taskType.toString()})
+ """.trimIndent())
}
+ buildFile.appendText("""
+ }
+ """.trimIndent())
}
}
diff --git a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt
index a54efa63..77ed5db1 100644
--- a/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt
+++ b/include-build/roborazzi-gradle-plugin/src/integrationTest/java/io/github/takahirom/roborazzi/RoborazziGradleProjectTest.kt
@@ -1,5 +1,7 @@
package io.github.takahirom.roborazzi
+import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
+import com.github.takahirom.roborazzi.RoborazziTaskType
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
@@ -472,4 +474,22 @@ class RoborazziGradleProjectTest {
checkResultCount(recorded = 1)
}
}
-}
\ No newline at end of file
+
+ @Test
+ fun shouldNotRecordResultsByDefault() {
+ RoborazziGradleProject(testProjectDir).apply {
+ unitTest()
+ checkResultsSummaryFileNotExists()
+ }
+ }
+
+ @OptIn(ExperimentalRoborazziApi::class)
+ @Test
+ fun shouldRecordResultsByDefaultIfExtensionIsConfigured() {
+ RoborazziGradleProject(testProjectDir).apply {
+ appBuildFile.taskType = RoborazziTaskType.Record
+ unitTest()
+ checkResultsSummaryFileExists()
+ }
+ }
+}
diff --git a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt
index 663aab28..3c5d0306 100644
--- a/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt
+++ b/include-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/RoborazziPlugin.kt
@@ -5,8 +5,10 @@ import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.github.takahirom.roborazzi.CaptureResult
import com.github.takahirom.roborazzi.CaptureResults
+import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.InternalRoborazziApi
import com.github.takahirom.roborazzi.RoborazziReportConst
+import com.github.takahirom.roborazzi.RoborazziTaskType
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
@@ -46,8 +48,10 @@ private const val DEFAULT_TEMP_DIR = "intermediates/roborazzi"
*/
open class RoborazziExtension @Inject constructor(objects: ObjectFactory) {
val outputDir: DirectoryProperty = objects.directoryProperty()
+ val taskType: Property |