Skip to content

Generated UI Espresso Test#1

Open
kbaldauf wants to merge 3 commits intomasterfrom
kb-generatedTestExample
Open

Generated UI Espresso Test#1
kbaldauf wants to merge 3 commits intomasterfrom
kb-generatedTestExample

Conversation

@kbaldauf
Copy link
Copy Markdown
Owner

@ChrisMM figured you might be interested in this. The Android Studio beta features a new Espresso Test Recorder that allows you generate automated UI tests by simply recording user interactions with a device.

The beta is currently a bit buggy as some manual changes need to be made to the generated code to get the test work correctly, but hopefully the issues will be worked out by the time the new tool gets out of beta. Even with the current issues, this makes writing UI tests on Android easier than ever before.

@ChrisMM
Copy link
Copy Markdown

ChrisMM commented Aug 31, 2016

@kbaldauf

Indeed. Thanks!

isDisplayed())) seems to be the way to go! 🚀

  1. /activity/NoPlayerFoundTest.java was recorded and generated?
  2. app/build.gradle was updated manually?

@kbaldauf
Copy link
Copy Markdown
Owner Author

kbaldauf commented Sep 1, 2016

@ChrisMM
So the app/build.gradle changes were simply one time changes that needed to be done to ensure the correct espresso dependencies are pulled into the project. This isn't out of the ordinary as this is just something that has to be done in Android anytime a new library is added to the project.

The bulk of the interesting stuff is what's happening in /activity/NoPlayerFoundTest.java. The majority of this file is automatically generated based off of how the Espresso Test Recorder saw that I used the app on my phone. As seen here, some slight adjustments needed to be made to the generated code though. For one, Android Studio was generating overly complicated logic for finding some of the views. I went in and manually simplified this logic since the over complication led to some occasionally failures. The generated code was also using hard coded strings so for the sake of maintainability and cleanliness, I replaced those hardcoded strings with references to the app's existing string resource files.

Even with doing those changes though, using the generated tests as a starting point was a lot faster than starting from scratch.

@ChrisMM
Copy link
Copy Markdown

ChrisMM commented Sep 1, 2016

@kbaldauf

Awesome 🚀 Great bottomline summary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants