Slide 1

Slide 1 text

Efficient Android testing @Alex_Zhukovich

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Setup Execution Verification Clean up

Slide 5

Slide 5 text

// setup var note = Note(“Hi!”, WARSAW_LAT, WARSAW_LON) // execution database.insert(note) // verification var result = database.getNotes() assertEquals(EXPECTED_NOTES, result) // clean up clearDatabase()

Slide 6

Slide 6 text

Android tests Local Instrumentation UI Non-UI Robolectric Espresso UiAutomator Appium Instrumentation API

Slide 7

Slide 7 text

UiAutomatorViewer Testing Android toolset

Slide 8

Slide 8 text

LayoutInspector Testing Android toolset

Slide 9

Slide 9 text

Installing and running test cases on device adb shell Instrumentation am instrument Application Test Application

Slide 10

Slide 10 text

Moving to test samples

Slide 11

Slide 11 text

Application overview

Slide 12

Slide 12 text

Authorization of the user - scenarios Test scenario #1: Enter correct auth data Test scenario #2: Enter incorrect auth data Test scenario #3: Enter incorrect auth data and handle them on client side

Slide 13

Slide 13 text

Authorization of the user – E2E

Slide 14

Slide 14 text

Authorization of the users – UI with mocking DATA

Slide 15

Slide 15 text

Authorization of the user – differences End-To-End test cases UI tests with mocking B Interaction with server Verification interaction with a server C Fast UI verification Fast and independent on resources tests A Entry point Start tests from the main screen B No interaction with server Verification UI and interaction with mock object A Entry point Start test from any screen of the app

Slide 16

Slide 16 text

Search notes - scenarios Test scenario #1: Display all notes Test scenario #2: Handle error during loading notes Test scenario #3: Display search results

Slide 17

Slide 17 text

Displaying all notes – E2E

Slide 18

Slide 18 text

Handle error during loading notes – E2E !

Slide 19

Slide 19 text

Display search results – E2E

Slide 20

Slide 20 text

Display all notes – UI with mocking DATA

Slide 21

Slide 21 text

Handle error during loading notes – UI with mocking DATA

Slide 22

Slide 22 text

Display search results – UI with mocking DATA

Slide 23

Slide 23 text

Search notes – differences End-To-End test cases UI tests cases with mocking B Interaction with server Verification interaction with a server A Entry point Start tests from the main screen C Data from the server Depend on data from the server E Fast UI verification Fast and independent on resources tests B No interaction with server Verification UI and interaction with mock object A Entry point Start test from any screen of the app D App architecture Architecture should support mocking C UI component verification Testing only fragments, view without main Activity

Slide 24

Slide 24 text

Should we use UI test with mocking everywhere?

Slide 25

Slide 25 text

Should we use UI tests with mocking everywhere? https://gph.is/1bkaInz

Slide 26

Slide 26 text

Scope of Regression testing

Slide 27

Slide 27 text

E2E test cases in scope of regression tests Specifications Analytical data

Slide 28

Slide 28 text

Efficient UI testing End To End tests UI tests +

Slide 29

Slide 29 text

Integration with an Android app

Slide 30

Slide 30 text

Custom AndroidJUnitRunner class MockTestRunner : AndroidJUnitRunner() { override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application { return Instrumentation.newApplication( MockMapNotesApp::class.java, context) } }

Slide 31

Slide 31 text

Configuring product flavors productFlavors { prod { ... versionNameSuffix "-prod" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } dev { ... versionNameSuffix "-dev" testInstrumentationRunner "com.alex.mapnotes.MockTestRunner" } }

Slide 32

Slide 32 text

Testing tips

Slide 33

Slide 33 text

The name matters

Slide 34

Slide 34 text

Learn existing test cases and maintain them

Slide 35

Slide 35 text

Verify positive and negative test cases

Slide 36

Slide 36 text

Verify business and navigation flows

Slide 37

Slide 37 text

Test only your code

Slide 38

Slide 38 text

Write test case base on specification, not on implementation

Slide 39

Slide 39 text

Stop testing manually, just automate it

Slide 40

Slide 40 text

Care about testability in the code

Slide 41

Slide 41 text

Q&A Espresso: https://developer.android.com/training/testing/espresso/ UiAutomator: https://developer.android.com/training/testing/ui-automator/ Appium: http://appium.io/ Android Testing codelab: https://codelabs.developers.google.com/codelabs/android-testing/ MapNotes: https://github.com/AlexZhukovich/MapNotes Blog: http://alexzh.com/ @Alex_Zhukovich