sergio-sastre / ComposablePreviewScanner

A library to help auto-generate screenshot tests from Composable Previews with any screenshot testing library: JVM-based (i.e. Paparazzi, Roborazzi) as well as Instrumentation-based (i.e. Shot, Dropshots, Android-Testify, etc.)
MIT License
121 stars 1 forks source link

Support @Previews inside classes #4

Open sergio-sastre opened 1 month ago

sergio-sastre commented 1 month ago

The most common scenario is to have @Previews as functions in a file, instead of defining them inside a class. So like this

// #1
@Composable
@Preview
fun CoffeeDrinkListPreview() {
        MyComposable(...)
}

instead of this

// #2
class PreviewsForScreenshotTests {
   @Composable
   @Preview
   fun CoffeeDrinkListPreview() {
           MyComposable(...)
   }
}

However, the # 2 is for example, what Google's Compose Preview Screenshot Testing tool requires to execute tests. This is currently not supported by ComposablePreviewScanner, and throws the following exception in that case

java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null

It'd be convenient to also support such case, so one can smoothly transition from one library to another