Android Testing
-
Upload
antoine-campbell -
Category
Software
-
view
343 -
download
0
Transcript of Android Testing
Others Talk, We Listen.
Android TestingAntoine Campbell
1
Overview
• Background• Testing Approaches and Demos
• Android Unit ( JUnit 3 )• JUnit 4• Robolectric ( JUnit 4 )• Instrumentation ( JUnit 3/ JUnit 4new )
• Espresso• Isolated Fragments ( why not, it works )
• UIAutomator ( JUnit 3/ JUnit 4new )• Pure (End-to-End capable)• Instrumentation
• Questions• Resources
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
2
Background
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
3
• UNC-Charlotte• B.A./M.S. Computer Science
• Android Developer• 2 client apps in prod, 4 supported
• iOS Developer• 1 enterprise app in prod
• Web Services (SOAP, REST)• 2 client apps in prod
• Game Developer (former)• CT native / NC native• CapTech Consulting – 3rd year
Android Unit (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
4
• Must extend TestCase, AndroidTestCase• Test methods must begin with ‘test’ e.g. ‘testMethod’• Runs on device• Full Android API available
Android Unit (JUnit 3) - DEMO
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
5
DEMO
JUnit 4
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
6
• Test methods must be annotated with @Test• Runs in JVM on host machine• Android API stub available
• All methods throw exceptions
JUnit 4
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
7
DEMO
Robolectric (JUnit 4)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
8
• Test methods must be annotated with @Test• Runs in JVM on host machine• Android API stub available (Robolectric implements some Android
APIs)
Robolectric (JUnit 4) – Android Studio Bug
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
9
• Newly created test have incorrect working directory • Should be set to $MODULE_DIR$
Robolectric (JUnit 4)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
10
DEMO
Instrumentation - Espresso (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
11• Must extend InstrumentationTestCase,
ActivityInstrumentationTestCase2<>• Test methods must begin with ‘test’ e.g. ‘testMethod’• Runs on device• Full Android API available
Instrumentation - Espresso (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
12
DEMO
Instrumentation – Isolated Fragments (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
13• Restrictions same as Instrumentation• Attach fragment to anonymous activity
Instrumentation – Isolated Fragments (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
14
DEMO
UIAutomator – Pure (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
15• Restrictions same as Instrumentation (InstrumentationTestCase)• Full access to entire device (muahahahahah)• Test can become tedious and flaky, yet powerful
UIAutomator – Pure (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
16
DEMO
UIAutomator – Instrumentation (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
17
• Restrictions same as Instrumentation (ActivityInstrumentationTestCase2)
• Full access to entire device (muahahahahah)• Even contexts your app does not own
• Activity started and stopped for you between tests
UIAutomator – Instrumentation (JUnit 3)
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
18
DEMO
Questions
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
19
Resources
Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
20
Demo App: https://github.com/antoinecampbell/GithubUserBroswerTesting Docs: http://developer.android.com/tools/testing/testing_android.htmlRobolectric: http://robolectric.org/Espresso: https://code.google.com/p/android-test-kit/Robotium: https://code.google.com/p/robotium/
Email / G+: [email protected] blog: http://antoine-campbell.com