To write agile android - testing is essential otherwise it quickly beocomes impossible to sperate code.
- Rule for launching activity
- Rule for launching service
- Testing a view - using Espresso
onView
perform
`` - Testing a spinner/listview/adapterView by itereating its values - using Espresso
onData
- Testing a RecyclerView - using Espresso
RecyclerViewActions
- Testing RX code
- Testing Contracts with - Mocks, Doubles, Stubs, Fakes and Shadows.
- Testing Behaviour not impleminatation -the Robot Patten.
- Dependency Injection.
- MVP - Desinging for testablilty.
- MVVM - Desinging for testablilty.
The Robot pattern Overview
Robot is based on Page objects
for web. It is a testing architecture for use with espresso.
The robot class is used to decouple the test code from the UI by abstracting the ui interactions from the test. When the UI changes threr is a minimal changes needed to maintain the tests.
ScreenRobot
- the generic abstract robot since we will need a robot per fragment/activity.LoginRobot
- the robot for our activity/fragment. Each user operation is abstracted by a single method in the robot. e.g. ** username enrty, ** password entry, ** remeber me, ** login button click.LoginActivityTest
- the test that uses the robot or roborts.
The MVP places an interface infront of the view and pulls out all non UI Code from Android activity into a Presenter
greatly simplifing and speeding up testing on the JVM.
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
@Rule public IntentsTestRule<MyActivity> intentsTestRule = new IntentsTestRule<>(MyActivity.class);