top | android | coffee | dealing_with_companies | dev_blog | experiments | food | fun | io15 | politics | products | random | security | startups | tech_events | thoughts | wearables |

08 Dec 2015, 09:11

Testing in Android

Share

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
  • Espresso

Refactor across unit and instrumentation tests.

Hermetic testing

isolate tests from external dependencies

Flaky tests are worse than no tests. (When it fails sometimes.)

Steps:

  1. Isolate from external dependencies
    • Especially the network
  2. Replace the components that talk to external dependencies, with things that replace with fake data
  3. Using product flavor ‘mockDebug’, with source sets
  4. 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

testing pyramid

Unit testing

unit test business logic

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

android 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);
comments powered by Disqus