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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rally screenshot tests #215

Closed
wants to merge 3 commits into from
Closed

Rally screenshot tests #215

wants to merge 3 commits into from

Conversation

pedrovgs
Copy link

@pedrovgs pedrovgs commented Oct 5, 2020

After the official alpha release announcement @JoseAlcerreca told us there was an opportunity to implement screenshot testing support in Jetpack Compose. Today I've finished the development of the feature and I've prepared a branch just to show you how any android developer could use this testing strategy to test their Compose components using Shot.

I do not expect this branch to be merged in this repository. I understand Shot is a tool you did not create, and you do not want to maintain in this repo. Feel free to close the PR if you want. However, I think this PR can be useful to gather some feedback about different testing strategies in Jetpack Compose.

Inside this PR you'll find the following changes:

  • Some bash scripts needed to initialize the same emulator the CI environment will use to verify the screenshots and the developer will use to record them.
  • Changes in the CI configuration to be able to start the emulator and run the screenshot tests.
  • A bunch of .png files with the screenshots recorded during the execution of our screenshot tests.
  • Changes needed to configure Shot in this project.
  • Screenshot tests for the following components: AccountsBody, AnimatedCircle, BillsBody, OverviewBody, RallyApp, and RallyTopAppBar.
  • In the case of AnimatedCircle, I've replaced the usage of the old screenshot testing tool with this new one which handles screenshots automatically for yow.

Apart from the coverage added there was some stuff I could not implement using screenshot testing:

  • I couldn't add coverage to the RallyAlertDialog component. onRoot method throws an exception whenever you try to invoke it with the dialog as the only component being part of the test. I don't know why this happens, but there is an exception thrown whenever you invoke onRoot complaining about two items being the root of the hierarchy.
  • It could be great if we could take a long screenshot with a bigger screen size so we don't have to scroll the view to the bottom in order to take a screenshot of a view with a long scroll. However, this is impossible with the current API. This is something we can do with regular android Views, but not supported for now in Compose.
  • The rule createComposeRule throws an exception if you try to invoke setContent more than once. This doesn't let us take more than one screenshot per test for different components. This is a pity, most of the tests we are going to write could use a custom screenshot name and be recorded inside the same test starting the activity only once and rendering different component instances. If we were able to do this, this could be a huge performance improvement in tests' execution time because we wouldn't need to start the activity once per test.
  • There are no examples in this branch, but this testing strategy is fully compatible with any mocking library you want to use in case there are some components with dependencies you want to test.

You can find more information in Shot's repository or the blog post we wrote about it.

I've already signed the CLA in case it is necessary. Thank you all for your hard work in Jetpack Compose. You are doing it great! 馃敐

@JoseAlcerreca
Copy link
Contributor

JoseAlcerreca commented Oct 5, 2020

Hey Pedro, this looks promising but I think it would make more sense in the Shot repo. The official samples are definitively not the place for them :)

Can we move the conversation somewhere else?

@pedrovgs
Copy link
Author

pedrovgs commented Oct 5, 2020

@JoseAlcerreca wherever you think it's helpful 馃槂

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

Successfully merging this pull request may close these issues.

None yet

3 participants