Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview annotation to automatically generate Paparazzi unit tests. #973

Open
apkelly opened this issue Jul 2, 2023 · 6 comments
Open

Preview annotation to automatically generate Paparazzi unit tests. #973

apkelly opened this issue Jul 2, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@apkelly
Copy link

apkelly commented Jul 2, 2023

Each of the composables in our app have an associated Preview in the file for rendering in the IDE. It'd be great if there was a new annotation I could apply to these previews, that would be read by the Paparazzi plugin, which would create a snapshot test for that composable.

e.g.

@Preview
@PaparazziAnnotation(test = "here_is_a_method_name")
@Composable
private fun Feature1Preview() {
    Feature1Screen()
}

would generate a unit test

    @Test
    fun here_is_a_method_name() {
        paparazzi.snapshot {
            Feature1Screen()
        }
    }

This means I could keep my Previews close to the composable they relate too, but also means I don't have to duplicate the parameters and code for a unit test. It'd also make keeping them in sync a zero cost exercise, not need to update my unit tests if the parameters change to the composable.

@vassilisimon
Copy link

You can do it with Showkase for now.

@apkelly
Copy link
Author

apkelly commented Jul 5, 2023

Doesn't Showkase add an extra activity to your app? I'd be interested if it's limited to just unit tests.

@ln-12
Copy link

ln-12 commented Jul 7, 2023

You can get the list of all (non private) preview composables from Showkase using Showkase.getMetadata().componentList. Each entry then has the component field which holds the actual preview composable (also see https://github.com/airbnb/Showkase#5-showkase-object).

I have setup a custom paparazzi screenshot test which iterates over all components and takes a snapshot of each.

The activity is just a way of displaying all previews inside the app.

@vassilisimon
Copy link

@jrodbx jrodbx added this to the 1.4 milestone Jul 16, 2023
@jrodbx jrodbx modified the milestones: 1.4, 1.4+ Sep 28, 2023
@jrodbx jrodbx modified the milestones: 1.4, 1.3.4 Mar 1, 2024
@geoff-powell geoff-powell modified the milestones: 1.3.4, 1.4 May 13, 2024
@jrodbx jrodbx modified the milestones: 1.4, 1.3.5 May 23, 2024
@jrodbx jrodbx modified the milestones: 1.3.5, 1.4 Oct 1, 2024
@sergio-sastre
Copy link

I'm the author of ComposablePreviewScanner, and it looks like it would perfectly help accomplish what is described in the example, likely much better than Showkase.

Roborazzi currently supports creating screenshot tests out of previews with ComposablePreviewScanner since 1.22.0 and I've got pretty good feedback from it. The integration was not very hard indeed and I'm also aware many projects currently use it with Paparazzi as well.

If you'd consider to integrate ComposablePreviewScanner in Paparazzi, I can gladly help with that.

@vassilisimon
Copy link

vassilisimon commented Oct 16, 2024

Would be amazing @sergio-sastre @jrodbx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants