On November 23 & 24, I attended the first ever Android Dev Summit. The following are notes that I took during talks. I have included the video of the talk as well. Again, these are my notes from the talk, not my original content.
Chiu-Ki Chan (Android GDE) took really great notes during the session as well, here’s what she had:
People want automated testing. Android has not provided a ton of testing APIs, and it hasn’t evolved much since API level 3. Until recently.
Android provided tools for testing:
- Android Studio / Gradle
- Android Testing Support Library
Refactor across unit and instrumentation tests.
Flaky tests are worse than no tests. (When it fails sometimes.)
- Isolate from external dependencies
- Especially the network
- Replace the components that talk to external dependencies, with things that replace with fake data
- Using product flavor ‘mockDebug’, with source sets
- Inject lives in both mock and prod source sets
When to use:
- Mock mode for manual testing & concurrent development
- Prod mode for end-to-end tests
- great pre-release check
Unit tests are fundamental. Run locally, generally fast, should be small and well contained. Focused on methods.
Don’t put everything into Activities, it makes it really hard to test. Move business logic out, so that it is more testable.
Mockable Android Jar.
Android Studio helps with Test-Driven-Development. If everything is set up correctly, AS can even help with new features, if tests are defined first.
UI Testing with Espresso
Integration and UI tests check your application through its interface. You need a device or emulator for this. CloutTest Lab allows you to test on real devices.
UI testing is hard! Espresso helps with this.
Tried to ask: What would a user do?
Find, perform, check
onView(ViewMatcher) .perform(ViewAction) .check(ViewAssertion);