Skip to content

Commit 07975b6

Browse files
Merge pull request #77 from sergio-sastre/release/2.0.0
Update Dropshots + Roborazzi & fix naming for cross-library tests without name
2 parents 8e83304 + 1b9b0ef commit 07975b6

File tree

20 files changed

+363
-332
lines changed

20 files changed

+363
-332
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ allprojects {
108108

109109
```groovy
110110
dependencies {
111-
androidTestImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0-rc1') {
111+
androidTestImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0') {
112112
// if necessary, add this to avoid compose version clashes
113113
exclude group: 'androidx.compose.ui'
114114
}
@@ -162,8 +162,8 @@ Configure your robolectric screenshot tests similar to how you'd do it with on-d
162162
For that, add the following dependencies in your `build.gradle`:
163163

164164
```kotlin
165-
testImplementation 'com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0-rc1'
166-
testImplementation 'com.github.sergio-sastre.AndroidUiTestingUtils:robolectric:2.0.0-rc1'
165+
testImplementation 'com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0'
166+
testImplementation 'com.github.sergio-sastre.AndroidUiTestingUtils:robolectric:2.0.0'
167167
```
168168

169169
If you get any error due to "Activity not found" in your application module, add the following to your `debug/manifest`
@@ -190,7 +190,7 @@ You can also add support for your own solution / another library by implementing
190190

191191
#### Basic configuration
192192
This section covers the basics: how to configure cross-library screenshot test that will run with the library of your choice. The main benefit is, that to switch to another library you won't need to rewrite all your tests!</br>
193-
It's possible to configure more though<sup>1</sup>. For shared screenshot tests (i.e. on-device + JVM), check [the next section](#shared-tests)</br></br>
193+
It's possible to configure several libraries though<sup>1</sup>. For shared screenshot tests (i.e. on-device + JVM), check [the next section](#shared-tests)</br></br>
194194

195195
1. First of all, configure all the screenshot testing libraries you want your tests to support, as
196196
if you'd write them with those specific libraries. Visit their respective Github pages for more info.
@@ -200,27 +200,27 @@ It's possible to configure more though<sup>1</sup>. For shared screenshot tests
200200

201201
```
202202
dependencies {
203-
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0-rc1')
203+
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:utils:2.0.0')
204204
205205
// NOTE: From here down, add only those for the libraries you're planning to use
206206
207207
// For Shot support
208-
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:shot:2.0.0-rc1')
208+
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:shot:2.0.0')
209209
210210
// For Dropshots support
211-
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:dropshots:2.0.0-rc1')
211+
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:dropshots:2.0.0')
212212
213213
// For Paparazzi support, AGP 8.0.0+ required
214-
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:mapper-paparazzi:2.0.0-rc1')
215-
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:paparazzi:2.0.0-rc1')
214+
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:mapper-paparazzi:2.0.0')
215+
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:paparazzi:2.0.0')
216216
217217
// For Roborazzi support
218-
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:mapper-roborazzi:2.0.0-rc1')
219-
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:robolectric:2.0.0-rc1')
220-
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:roborazzi:2.0.0-rc1')
218+
debugImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:mapper-roborazzi:2.0.0')
219+
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:robolectric:2.0.0')
220+
testImplementation('com.github.sergio-sastre.AndroidUiTestingUtils:roborazzi:2.0.0')
221221
}
222222
```
223-
If using Roborazzi, enable robolectric native graphics throug gradle as well
223+
If using Roborazzi, enable robolectric native graphics through gradle as well
224224

225225
```groovy
226226
android {
@@ -266,9 +266,8 @@ But if you wish to configure many on-device or many JVM libraries at the same ti
266266

267267

268268
#### Shared tests
269-
If instead of using just one library at once, you want to enable shared tests (i.e same test running either on the JVM or on a device/emulator),you have 2 options to share resources between unitTests and AndroidTests:
270-
1. Create and write your tests in a [share test module as described here](https://blog.danlew.net/2022/08/16/sharing-code-between-test-modules/) or...
271-
2. Add this in the `build.gradle` of the module where you'll write shared tests and then write your screenshot tests under `src/sharedTest`.
269+
If instead of using just one screenshot testing library at once, you want to enable shared tests (i.e same test running either on the JVM or on a device/emulator),you have to share resources between unitTests and AndroidTests.</br>
270+
The easiest way is to add this in the `build.gradle` of the module where you'll write shared tests and then write your screenshot tests under `src/sharedTest`,
272271

273272
```groovy
274273
android {
@@ -283,6 +282,8 @@ android {
283282
}
284283
}
285284
```
285+
> **Warning**</br>
286+
> Android Studio will show errors if sharedTests are defined in an application module. Consider creating an extra library module for testing the UI of your application module.
286287
287288
Now follow steps 1. & 2. as in the [Basic configuration](#basic-configuration) section. After that:
288289

dropshots/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
defaultConfig {
1212
minSdk 23
1313
targetSdk 33
14-
versionCode 20
15-
versionName "2.0.0-rc1"
14+
versionCode 21
15+
versionName "2.0.0"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}
@@ -44,7 +44,7 @@ android {
4444
dependencies {
4545
implementation project(':utils')
4646
implementation 'androidx.test:rules:1.5.0'
47-
api 'com.dropbox.dropshots:dropshots:0.4.0'
47+
api 'com.dropbox.dropshots:dropshots:0.4.1'
4848
api 'androidx.activity:activity-compose:1.7.1'
4949
}
5050

@@ -54,7 +54,7 @@ publishing {
5454
release(MavenPublication) {
5555
groupId = 'com.github.sergio-sastre'
5656
artifactId = "dropshots"
57-
version = '2.0.0-rc1'
57+
version = '2.0.0'
5858

5959
afterEvaluate {
6060
from components.release

dropshots/src/main/AndroidManifest.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

dropshots/src/main/java/sergio/sastre/uitesting/dropshots/DropshotsAPI29Fix.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.

dropshots/src/main/java/sergio/sastre/uitesting/dropshots/DropshotsConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ class DropshotsConfig(
1313
val imageComparator: ImageComparator = SimpleImageComparator(maxDistance = 0.004f),
1414
val bitmapCaptureMethod: BitmapCaptureMethod? = null,
1515
@ColorInt val backgroundColor: Int? = null,
16+
val filePath: String? = null,
1617
) : LibraryConfig

dropshots/src/main/java/sergio/sastre/uitesting/dropshots/DropshotsScreenshotTestRuleForComposable.kt

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package sergio.sastre.uitesting.dropshots
22

3-
import android.graphics.Bitmap
4-
import android.view.View
53
import androidx.compose.runtime.Composable
6-
import androidx.core.view.drawToBitmap
74
import com.dropbox.dropshots.Dropshots
85
import org.junit.rules.RuleChain
96
import org.junit.runner.Description
107
import org.junit.runners.model.Statement
11-
import sergio.sastre.uitesting.utils.crosslibrary.config.BitmapCaptureMethod
128
import sergio.sastre.uitesting.utils.crosslibrary.config.LibraryConfig
139
import sergio.sastre.uitesting.utils.crosslibrary.config.ScreenshotConfigForComposable
1410
import sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioForComposableRule
1511
import sergio.sastre.uitesting.utils.crosslibrary.testrules.ScreenshotTestRuleForComposable
16-
import sergio.sastre.uitesting.utils.utils.drawToBitmapWithElevation
1712

1813
class DropshotsScreenshotTestRuleForComposable(
1914
override val config: ScreenshotConfigForComposable = ScreenshotConfigForComposable(),
@@ -26,8 +21,8 @@ class DropshotsScreenshotTestRuleForComposable(
2621
)
2722
}
2823

29-
private val dropshotsRule: DropshotsAPI29Fix by lazy {
30-
DropshotsAPI29Fix(
24+
private val dropshotsRule: ScreenshotTaker by lazy {
25+
ScreenshotTaker(
3126
Dropshots(
3227
resultValidator = dropshotsConfig.resultValidator,
3328
imageComparator = dropshotsConfig.imageComparator,
@@ -60,33 +55,11 @@ class DropshotsScreenshotTestRuleForComposable(
6055
.setContent(composable)
6156
.composeView
6257

63-
when (val bitmapCaptureMethod = dropshotsConfig.bitmapCaptureMethod) {
64-
is BitmapCaptureMethod.Canvas ->
65-
takeSnapshotWithCanvas(bitmapCaptureMethod.config, composeView, name)
66-
is BitmapCaptureMethod.PixelCopy ->
67-
takeSnapshotWithPixelCopy(bitmapCaptureMethod.config, composeView, name)
68-
null -> takeSnapshotOfView(composeView, name)
69-
}
70-
}
71-
72-
private fun takeSnapshotOfView(view: View, name: String?) {
73-
dropshotsRule.assertSnapshot(
74-
view = view,
75-
name = name ?: view::class.java.name,
76-
)
77-
}
78-
79-
private fun takeSnapshotWithPixelCopy(bitmapConfig: Bitmap.Config, view: View, name: String?) {
80-
dropshotsRule.assertSnapshot(
81-
bitmap = view.drawToBitmapWithElevation(config = bitmapConfig),
82-
name = name ?: view::class.java.name,
83-
)
84-
}
85-
86-
private fun takeSnapshotWithCanvas(bitmapConfig: Bitmap.Config, view: View, name: String?) {
8758
dropshotsRule.assertSnapshot(
88-
bitmap = view.drawToBitmap(config = bitmapConfig),
89-
name = name ?: view::class.java.name,
59+
view= composeView,
60+
bitmapCaptureMethod = dropshotsConfig.bitmapCaptureMethod,
61+
name = name,
62+
filePath = dropshotsConfig.filePath,
9063
)
9164
}
9265

0 commit comments

Comments
 (0)