The things to remember not to forget when you're testing Android apps

A presentation at Notts Test in September 2018 in Nottingham, UK by Graham Smith

Slide 1

Slide 1

The things to remember not to forget when you're testing Android apps

Slide 2

Slide 2

Who are we?

Who are we? Graham Smith @whoisgraham Matthew Herod @matthewherod

Slide 3

Slide 3

JOIN IN Feel free to say “me too!” or to add other ideas in as we go!

Slide 4

Slide 4

What did I forget to test? LET’S TAKE AN SEMI-ANECDOTAL WALK TOGETHER

Slide 5

Slide 5

1 That time my notes App lost its notes... Ah! A Classic!

Slide 6

Slide 6

Using Google Keep, went to test an App feature by enabling the “Dont keep activities setting” returned to Google Keep with all notes lost...

Slide 7

Slide 7

SO WHAT HAPPENED? ▪ Android lifecycle events ▪ Don’t keep activities simulates your app being stopped due to low memory etc ▪ Need to write code to store inputs when this occurs.

https://developer.android.com/guide/components/activities/activity-lifecycle

Slide 8

Slide 8

How can I test this?

Enable developer options on the device.

Go to Developer Settings Enable “Don’t keep activities”

Slide 9

Slide 9

2 That time App crashed when it wasn’t on the screen Yup another classic!

Slide 10

Slide 10

Quite a classic example where something async normally tries to update the view after its gone

Slide 11

Slide 11

So What Happened?

▪ Kick off some async process ▪ App no longer has Device focus ▪ After the async process finishes it tries to update the view. ▪ User receives a nasty NPE

Slide 12

Slide 12

▪ How can I test this? ▪ Unit tests for the code! ▫ ▪ Make use of Kotlin’s nullability operators Place your screenshot here Manual testing/UI testing possible but not so easy 12

Slide 13

Slide 13

3 That time App crashed when I rotated the screen But I like landscape...

Slide 14

Slide 14

Did you know? Your Activity gets recreated on rotation! But there are caveats and other options.

Slide 15

Slide 15

SO WHAT HAPPENED?

▪ The screen is rotated ▪ App loses state or get a bit confused ▪ User receives a nasty NPE or the UI doesn’t reflect the right state.

Slide 16

Slide 16

How can I test this? ▪Lock it to portrait ▫ ▫ The “painting over the stain solution”

▪ Look at what state is being held on to ▪ Unit testing - Seriously do it!

▪ UI Automation tests ▫ Espresso has support for this

Slide 17

Slide 17

This is a BIG topic… Be careful if you use configChanges in your manifest https://stackoverflow.com/questions/456211/activity-restart-on-rotation-android

Slide 18

Slide 18

4 That time we shipped a new feature that immediately crashed

Slide 19

Slide 19

We all make mistakes… Time pressures & feature flagging hid an issue in the release build of the App caused by obfuscated code.

Slide 20

Slide 20

SO WHAT HAPPENED? ▪ Feature flagged a feature to “ON” ▪ Users pressed the new menu item ▪ App crashed immediately

Slide 21

Slide 21

Be careful not to forget proguard

What is Proguard? Proguard is used to minify and obfuscate the Java code when creating a release build.

Proguard is a really helpful tool!

Slide 22

Slide 22

Slide 23

Slide 23

How can I fix this? Test the live release! We made a mistake - it was easy to fix. Luckily we have staged rollouts so the impact was minimal to the whole user base.

Slide 24

Slide 24

5 Odds and Evens - Android Fragmentation gotchas... A quick example, one of many...

Slide 25

Slide 25

Android 6 introduced the requirement of a special flag when starting an App from a background process or notification. They removed it in 7. They brought it back in 8+

Slide 26

Slide 26

SO WHAT HAPPENED? ▪ One to remember while in development ▪ Users interacts with a notification that opens an App. ▪ Android 5 & 7 works fine without the flag ▪ Android 6 & 8 crash.

Slide 27

Slide 27

So what do I do about it? Remember to add the flag! Make sure the code has the following OR use another mechanism! intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Remember to test on multiple Android versions! But you do this anyway… right?

Slide 28

Slide 28

6 Application stacks, task affinities and the UX Brace yourselves...

Slide 29

Slide 29

Slide 30

Slide 30

Slide 31

Slide 31

Slide 32

Slide 32

How can I fix this? Remember check the launch mode of the Activity! There are lots of different modes that change the way Android creates Activities. In the example before we reuse the existing Activity so to keep memory use down. Learn about Android Tasks Check out the Android documentation: https://developer.android.com/guide/components/activities/ tasks-and-back-stack

Slide 33

Slide 33

7 Migration Testing

Slide 34

Slide 34

Your app probably stores data, like databases and preferences. Make sure your app updates are compatible with data created by previous versions, or implement a migration!

Slide 35

Slide 35

SO WHAT HAPPENED? ▪ Your App stored some data in a database ▪ An update is released with changes to the database schema ▪ The App updates and now the app doesn’t understand it’s own database Schema Change ▪ Either an error or data loss!

Slide 36

Slide 36

▪ How can I test this? ▪ Before publishing a new version run your old version and then install the new version over the top. Does everything still work? ▪ Consider that installing version v7 of your app over version v2 or your app may also produce the same issue. ▪ It’s boring but it’s important!

Slide 37

Slide 37

Thanks! ANY QUESTIONS?