takahirom / roborazzi

Make JVM Android integration test visible 🤖📸
https://takahirom.github.io/roborazzi/
Apache License 2.0
654 stars 25 forks source link

Testing on different devices #281

Open kataRebuy opened 3 months ago

kataRebuy commented 3 months ago

Currently, if I want to test the same stuff on 3 different devices I have to write the tests 3 times. It would be nice to get a feature where you can run the same test with different device configs. Like this:

@Config(qualifiers = listOf(Pixel5, SmallPhone))

Of course then including the device config name in the screenshots file name to be able to distinguish between them.

takahirom commented 3 months ago

It's a reasonable approach. For now, we can refer to the implementation used by Now In Android for multi-device testing. In a nutshell, we can use RuntimeEnvironment.setQualifiers() as follows: RuntimeEnvironment.setQualifiers("w${width}dp-h${height}dp-${dpi}dpi").

https://github.com/android/nowinandroid/blob/bd89507f10f4f569bcb0af157135351ed2c4e5ce/core/screenshot-testing/src/main/kotlin/com/google/samples/apps/nowinandroid/core/testing/util/ScreenshotHelper.kt#L52

takahirom commented 3 months ago

We can integrate the multi-device feature into Roborazzi if we find a suitable API. Currently, however, I don't have one. You can utilize the roboOutputName() function to retrieve the default name of the Roborazzi image, which allows you to append the device name to it.

kataRebuy commented 3 months ago

That is a nice solution. It would be convenient if it were part of the library.

takahirom commented 3 months ago

We already have that function, but I didn't mention it in the document. So, now is the time to include it. https://github.com/search?q=repo%3Atakahirom%2Froborazzi%20roboOutputName&type=code

sergio-sastre commented 3 months ago

@kataRebuy In case it helps: did write about that (and more) here 👇 https://sergiosastre.hashnode.dev/efficient-testing-with-robolectric-roborazzi-across-many-ui-states-devices-and-configurations