android testing patterns
TRANSCRIPT
ANDROID TESTING
Chris Bowling
CONSIDERATIONS
Define
Unit Test
Instrumentation
Integration
Functional
Component
UI
Decouple
Code needs to be written with testing in mind
Decouple your code and from Android as much as possible
How?
1. Reduce dependencies on Android, fragments
2. Leverage libraries (Dagger, Butterknife, Robobindings)
CONSIDERATIONS
Defend
Establish clear component boundaries
Unit tests? – do they have Android dependencies
Leverage testing libriaries (Jmockit, WireMock, Robolectric, Appium)
Deploy
Precommit builds – run unit tests, lint
Continuous or Nightly jobs – run integration and UI tests
Releases – get your builds out there
1. Alpha and beta builds
2. Frequent production releases
CASE STUDIESConsideration Case 1 Case 2
Define -Unit: fast
-Functional: slow
-95%+ code coverage mandate
-Code reviews before commit
-Unit:No android dependencies
-Integration: boundaries around components
-UI: Fully end to end
-No code coverage mandate
Decouple -Very coupled
-Code and then write tests to get coverage
-Decoupled code
-Dagger all the things
-No fragments
-Decoupled from Android
Defend -Use all the things
-Do all the things
-Just get 95% coverage
-Each component had clear responsibilities
-Reduced need for unit tests
-Small integration tests
Deploy -Precommit builds run all tests
-Nightly builds
-Two week release cycle
-Precommit build runs Unit tests
-Continuous builds run integration and UI tests
-Daily alpha / Weekly beta builds
-Two week release cycle
TAKE AWAYS
One size does not fit all - find a solution that works for your team and take ownership
Testing is like an exercise program – you get results when you stick with it
Any step forward is a step in the right direction
eCG android tests
Testing Pyramid
End-to-End Test
Integration Tests
Unit Tests
Unit Tests
True Unit Tests – use BDD principals
~2200 tests /~40 seconds
Running with jUnit (not on emulator)
Dependency Injection
Mocking using Mockito
Ctor injection
MVP pattern for testing UI logic
Use Robolectic to allow for mocked android components
Shared prefs, app instance, etc
Avoid mocking Fragments/Activities/Views
UI Tests
Full end to end tests
Uses BDD principals
Cucumber driver running Espresso
Built and maintained by QE engineers
60% app coverage, runs in ~4.5 hours
Integration Tests
Creation in progress
BDD tests using cucumber – same as UI tests
Will inject the network layer to allow for faster and more robust tests
Ben Yarger
QE Lead
eBay for Charity
Bio
• 4 years at eBay
• RedLaser SDK (Android & iOS)
• Mobile Architecture (Android)
• eBay for Charity (full stack)
View
Controller
Model
Vie
w It
em
Sear
ch
Ch
eck
ou
t
Cu
sto
mer
Co
nn
ecti
on
AppServices
Customer Connection
Checkout
Search
View Item