SlideShare a Scribd company logo
1 of 20
Download to read offline
Testing on Android
Ari Lacenski
July 21, 2014
I <3 Android
• CodePath August 2013
• Then: EroGear LED control app
• Now: Android lead at Mango Health
Today
• Why test Android projects? What’s your approach?
• Android testing libraries
• How to write tests
• How to automate test runs
TDD and BDD
• TDD seems like a tough goal. Start small!
• BDD creates strong functional tests
• Behavior-driven dev healthy testing practices
Test-Driven
Development
Your goal? Release with confidence.
Behavior-Driven
Development
What to test
• Identify activity pathways in your app
• Test user stories with BDD strategies
• Test concepts like:
• button clicks perform actions
• content is drawn on screen
• an intent was launched and finished as expected
Database & services
What to test
Data persistence
Activities
Business logic
JUnit
JUnit
Robolectric, Robotium
JUnit
Which library is best?
• Robolectric is fast: no emulator required
• Robotium offers flexibility, if the emulator doesn’t bog
you down
Robolectric, Robotium, Android built-in tests, Mockito...?
OK to use more than one! You’ll probably have to.
BDD: Robolectric first , then Robotium.
Don’t forget plain old JUnit.
Robotium
<instrumentation	
  
	
  	
  	
  	
  android:name="android.test.InstrumentationTestRunner"	
  
	
  	
  	
  	
  android:targetPackage="net.tensory.justevents"	
  />
• Starts its own emulator or can be run on your Android
device... so it’s slow
public	
  class	
  MainActivityTest	
  extends	
  
	
  	
  	
  	
  ActivityInstrumentationTestCase2<MainActivity>	
  {
• Runs as separate Android project linked to main
from JustEventsRobotiumTest/.../MainActivityTest.java
from JustEventsRobotiumTest/AndroidManifest.xml
• Based on Android Instrumentation built-in tests
• Provides implementation for Android native methods,
lets you write behavior tests that use them directly
• Runs as a JUnit test project, not an Android app
• Fast! No emulator necessary
• Where it works, it’s awesome
Robolectric
http://www.slideshare.net/tylerschultz/robolectric-
android-unit-testing-framework
from 2011
Robolectric background
from 2010
(more code examples, but a little dated)
http://www.slideshare.net/
joemoore1/tdd-android-applications-with-robolectric
Good Ideas in Testing
• Multiple assertions per test are OK
• Test only one concept per test method
• You can write multiple test methods for one UI story
• Don’t test other libraries’code
• Look for ways to simplify your tests
private	
  Solo	
  solo;	
  
	
   	
  
public	
  MainActivityTest()	
  {	
  
super(MainActivity.class);	
  
}	
  
	
   	
  
@Before	
  
protected	
  void	
  setUp()	
  throws	
  Exception	
  {	
  
	
   super.setUp();	
  
	
   solo	
  =	
  new	
  Solo(getInstrumentation(),	
  getActivity());	
  
}	
  
!
@Test	
  
public	
  void	
  testFBFailedLoginReturnsToErrorView()	
  {	
  
	
   MainActivity	
  activity	
  =	
  getActivity();	
  
	
   int	
  errorResultCode	
  =	
  0;	
  
	
   int	
  fakeRequestCode	
  =	
  64208;	
  
	
   activity.onActivityResult(fakeRequestCode,	
  errorResultCode,	
  	
  
	
   	
   new	
  Intent());	
  
!
	
   TextView	
  tvError	
  =	
  (TextView)	
  
	
   activity.findViewById(R.id.tv_login_error);	
  
	
   String	
  text	
  =	
  (String)	
  tvError.getText();	
  
	
   assertThat(text,	
  equalTo(activity.getResources().	
  	
   	
   	
   	
  
	
   	
   getString(R.string.txt_login_error)));	
  
}
Then…
yay
Building with Tests
The goal of test coverage is to avoid manual work.
How do you run automated tests?
Continuous integration!
You rang, sir?
Your Basic CI Setup
Write tests in your IDE
Commit projects to a build server
Run build scripts
Deploy tested .apk as dev build
Eclipse, Android Studio
Jenkins with Git hooks
Jenkins
Hockey, XL Studio
Details on the CodePath wiki!
https://github.com/thecodepath/android_guides/wiki/
Building-Gradle-Projects-with-Jenkins-CI
Using Gradle?
• Running CI with Gradle, you can configure build.gradle
to run your Robolectric and your JUnit tests
• Develop locally in Android Studio
• Run tests with
• Then push the dev configuration to your CI
environment’s build.gradle file
You really should…
gradle build
http://blog.blundell-apps.com/android-gradle-app-with-
robolectric-junit-tests/
Set up deployment tool to distribute .apk
(XL Studio or HockeyApp)
Setup Flow
Write a build script that sends .apk
from Jenkins to deployment tool
Configure Jenkins to:
!
Write test projects1
2
3
4
1. run test projects as part of build
2. start a new build whenever you push code
Your Day-to-Day
Write tests and features Push code to repo
Jenkins runs the test projects
as part of the .apk build
Nope
Yup
New .apk gets sent out to
deployment tool
Read Jenkins logs
Try, try again
Trigger Jenkins
Build succeeded?
Tests passed?
Robotium in CI?
• Configure Jenkins to launch an emulator
• Use the Android Emulator Plugin
• Big thanks to Nathan & Tim
• Contribute to the CodePath wiki!
!
• Stay in touch?
• Also, we’re hiring.
https://github.com/thecodepath/android_guides
and @tensoryalacenski@gmail.com
ari@mangohealth.com

More Related Content

What's hot

プレゼンビフォアアフタ
プレゼンビフォアアフタプレゼンビフォアアフタ
プレゼンビフォアアフタTsuyoshi Ushio
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android StudioMichael Pan
 
Automation Open Source tools
Automation Open Source toolsAutomation Open Source tools
Automation Open Source toolsQA Club Kiev
 
Comparison between Eclipse and Android Studio for Android Development
Comparison between Eclipse and Android Studio for Android DevelopmentComparison between Eclipse and Android Studio for Android Development
Comparison between Eclipse and Android Studio for Android DevelopmentWillow Cheng
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsDominik Dary
 
Android – As a tool of innovation
Android – As a tool of innovation Android – As a tool of innovation
Android – As a tool of innovation Pallab Sarkar
 
Debot android debugging library
Debot android debugging libraryDebot android debugging library
Debot android debugging libraryTomoaki Imai
 
Selendroid in Action
Selendroid in ActionSelendroid in Action
Selendroid in ActionDominik Dary
 
Mobile WebDriver Selendroid
Mobile WebDriver SelendroidMobile WebDriver Selendroid
Mobile WebDriver SelendroidDominik Dary
 
Agile Testing at eBay
Agile Testing at eBayAgile Testing at eBay
Agile Testing at eBayDominik Dary
 
Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Hong Le Van
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...DicodingEvent
 
Testing Android App Bundle with Appium
Testing Android App Bundle with AppiumTesting Android App Bundle with Appium
Testing Android App Bundle with AppiumMasayuki Wakizaka
 
Testing Android
Testing AndroidTesting Android
Testing AndroidMarc Chung
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questionsKuldeep Pawar
 
Changes in programmer tools' infrastructure
Changes in programmer tools' infrastructureChanges in programmer tools' infrastructure
Changes in programmer tools' infrastructureAndrey Karpov
 
Applied Testing Heuristics in the Context of eBay
Applied Testing Heuristics in the Context of eBayApplied Testing Heuristics in the Context of eBay
Applied Testing Heuristics in the Context of eBayDominik Dary
 

What's hot (20)

Testing on Android
Testing on AndroidTesting on Android
Testing on Android
 
プレゼンビフォアアフタ
プレゼンビフォアアフタプレゼンビフォアアフタ
プレゼンビフォアアフタ
 
Introduction to Android Studio
Introduction to Android StudioIntroduction to Android Studio
Introduction to Android Studio
 
Automation Open Source tools
Automation Open Source toolsAutomation Open Source tools
Automation Open Source tools
 
Comparison between Eclipse and Android Studio for Android Development
Comparison between Eclipse and Android Studio for Android DevelopmentComparison between Eclipse and Android Studio for Android Development
Comparison between Eclipse and Android Studio for Android Development
 
Implementing Test Automation in Agile Projects
Implementing Test Automation in Agile ProjectsImplementing Test Automation in Agile Projects
Implementing Test Automation in Agile Projects
 
Android – As a tool of innovation
Android – As a tool of innovation Android – As a tool of innovation
Android – As a tool of innovation
 
The Test way
The Test wayThe Test way
The Test way
 
Debot android debugging library
Debot android debugging libraryDebot android debugging library
Debot android debugging library
 
Selendroid in Action
Selendroid in ActionSelendroid in Action
Selendroid in Action
 
Mobile WebDriver Selendroid
Mobile WebDriver SelendroidMobile WebDriver Selendroid
Mobile WebDriver Selendroid
 
Agile Testing at eBay
Agile Testing at eBayAgile Testing at eBay
Agile Testing at eBay
 
Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012
 
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
 
Testing Android App Bundle with Appium
Testing Android App Bundle with AppiumTesting Android App Bundle with Appium
Testing Android App Bundle with Appium
 
Testing Android
Testing AndroidTesting Android
Testing Android
 
Webinar on Google Android SDK
Webinar on Google Android SDKWebinar on Google Android SDK
Webinar on Google Android SDK
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
 
Changes in programmer tools' infrastructure
Changes in programmer tools' infrastructureChanges in programmer tools' infrastructure
Changes in programmer tools' infrastructure
 
Applied Testing Heuristics in the Context of eBay
Applied Testing Heuristics in the Context of eBayApplied Testing Heuristics in the Context of eBay
Applied Testing Heuristics in the Context of eBay
 

Viewers also liked

Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...SoftServe
 
Performance Testing on Android
Performance Testing on AndroidPerformance Testing on Android
Performance Testing on AndroidAkshay Dashrath
 
Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14Alex Gaber
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android TestingFernando Cejas
 
Unit testing in android
Unit testing in androidUnit testing in android
Unit testing in androidLi-Wei Cheng
 
How to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android GamesHow to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android GamesBitbar
 
Mobile testing
Mobile testingMobile testing
Mobile testingAlex Hung
 
browser compatibility testing
browser compatibility testingbrowser compatibility testing
browser compatibility testingLakshmi Nandoor
 
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...Sauce Labs
 
7 1-1 soap-developers_guide
7 1-1 soap-developers_guide7 1-1 soap-developers_guide
7 1-1 soap-developers_guideNugroho Hermanto
 
Web Application Software Testing
Web Application Software TestingWeb Application Software Testing
Web Application Software TestingAndrew Kandels
 
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Tom Eston
 
Mobile applications testing
Mobile applications testingMobile applications testing
Mobile applications testingRahul Ranjan
 
Testing Mobile Apps
Testing Mobile AppsTesting Mobile Apps
Testing Mobile AppsSuresh Kumar
 

Viewers also liked (19)

Introduction to android testing
Introduction to android testingIntroduction to android testing
Introduction to android testing
 
Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...Android Mobile Application Testing: Specific Functional, Performance, Device ...
Android Mobile Application Testing: Specific Functional, Performance, Device ...
 
Performance Testing on Android
Performance Testing on AndroidPerformance Testing on Android
Performance Testing on Android
 
Android performance
Android performanceAndroid performance
Android performance
 
Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14Android Performance and Monitoring - Meetup 3 25-14
Android Performance and Monitoring - Meetup 3 25-14
 
Inside Android Testing
Inside Android TestingInside Android Testing
Inside Android Testing
 
Android testing
Android testingAndroid testing
Android testing
 
Testing Android Security
Testing Android SecurityTesting Android Security
Testing Android Security
 
Unit testing in android
Unit testing in androidUnit testing in android
Unit testing in android
 
How to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android GamesHow to Reliably Measure and Optimize Graphics Performance of Your Android Games
How to Reliably Measure and Optimize Graphics Performance of Your Android Games
 
Web testing
Web testingWeb testing
Web testing
 
Mobile testing
Mobile testingMobile testing
Mobile testing
 
browser compatibility testing
browser compatibility testingbrowser compatibility testing
browser compatibility testing
 
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
Compatibility Testing of Your Web Apps - Tips and Tricks for Debugging Locall...
 
7 1-1 soap-developers_guide
7 1-1 soap-developers_guide7 1-1 soap-developers_guide
7 1-1 soap-developers_guide
 
Web Application Software Testing
Web Application Software TestingWeb Application Software Testing
Web Application Software Testing
 
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
Don't Drop the SOAP: Real World Web Service Testing for Web Hackers
 
Mobile applications testing
Mobile applications testingMobile applications testing
Mobile applications testing
 
Testing Mobile Apps
Testing Mobile AppsTesting Mobile Apps
Testing Mobile Apps
 

Similar to Testing on Android

Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle ManagementAmazon Web Services
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionFernando Cejas
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Editionpenanochizzo
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnitsatejsahu
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012Justin Gordon
 
Android workshop
Android workshopAndroid workshop
Android workshopSagar Patel
 
Mobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMoataz Nabil
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScriptRob Scaduto
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsAmazon Web Services
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsAmazon Web Services
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesSolstice Mobile Argentina
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going BaldDavid Carver
 
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Sauce Labs
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automationVishal Banthia
 
When & How to Successfully use Test Automation for Mobile Applications
When & How to Successfully use Test Automation for Mobile ApplicationsWhen & How to Successfully use Test Automation for Mobile Applications
When & How to Successfully use Test Automation for Mobile ApplicationsTechnologyAssociationOregon
 
MobileCity:Introduction to IOS
MobileCity:Introduction to IOSMobileCity:Introduction to IOS
MobileCity:Introduction to IOSAllan Davis
 
Automation Proposal_V1.0
Automation Proposal_V1.0Automation Proposal_V1.0
Automation Proposal_V1.0Dao Nhỏ
 
Building High Quality Android Applications
Building High Quality Android ApplicationsBuilding High Quality Android Applications
Building High Quality Android ApplicationsLeif Janzik
 

Similar to Testing on Android (20)

Android testing
Android testingAndroid testing
Android testing
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle Management
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Edition
 
How ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second EditionHow ANDROID TESTING changed how we think about Death - Second Edition
How ANDROID TESTING changed how we think about Death - Second Edition
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Mobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and DockerMobile UI Testing using Appium and Docker
Mobile UI Testing using Appium and Docker
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScript
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
Innovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best PracticesInnovation Generation - The Mobile Meetup: Android Best Practices
Innovation Generation - The Mobile Meetup: Android Best Practices
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going Bald
 
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automation
 
When & How to Successfully use Test Automation for Mobile Applications
When & How to Successfully use Test Automation for Mobile ApplicationsWhen & How to Successfully use Test Automation for Mobile Applications
When & How to Successfully use Test Automation for Mobile Applications
 
MobileCity:Introduction to IOS
MobileCity:Introduction to IOSMobileCity:Introduction to IOS
MobileCity:Introduction to IOS
 
Android class provider in mumbai
Android class provider in mumbaiAndroid class provider in mumbai
Android class provider in mumbai
 
Automation Proposal_V1.0
Automation Proposal_V1.0Automation Proposal_V1.0
Automation Proposal_V1.0
 
Building High Quality Android Applications
Building High Quality Android ApplicationsBuilding High Quality Android Applications
Building High Quality Android Applications
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Testing on Android

  • 1. Testing on Android Ari Lacenski July 21, 2014
  • 2. I <3 Android • CodePath August 2013 • Then: EroGear LED control app • Now: Android lead at Mango Health
  • 3. Today • Why test Android projects? What’s your approach? • Android testing libraries • How to write tests • How to automate test runs
  • 4. TDD and BDD • TDD seems like a tough goal. Start small! • BDD creates strong functional tests • Behavior-driven dev healthy testing practices Test-Driven Development Your goal? Release with confidence. Behavior-Driven Development
  • 5. What to test • Identify activity pathways in your app • Test user stories with BDD strategies • Test concepts like: • button clicks perform actions • content is drawn on screen • an intent was launched and finished as expected
  • 6. Database & services What to test Data persistence Activities Business logic JUnit JUnit Robolectric, Robotium JUnit
  • 7. Which library is best? • Robolectric is fast: no emulator required • Robotium offers flexibility, if the emulator doesn’t bog you down Robolectric, Robotium, Android built-in tests, Mockito...? OK to use more than one! You’ll probably have to. BDD: Robolectric first , then Robotium. Don’t forget plain old JUnit.
  • 8. Robotium <instrumentation          android:name="android.test.InstrumentationTestRunner"          android:targetPackage="net.tensory.justevents"  /> • Starts its own emulator or can be run on your Android device... so it’s slow public  class  MainActivityTest  extends          ActivityInstrumentationTestCase2<MainActivity>  { • Runs as separate Android project linked to main from JustEventsRobotiumTest/.../MainActivityTest.java from JustEventsRobotiumTest/AndroidManifest.xml • Based on Android Instrumentation built-in tests
  • 9. • Provides implementation for Android native methods, lets you write behavior tests that use them directly • Runs as a JUnit test project, not an Android app • Fast! No emulator necessary • Where it works, it’s awesome Robolectric
  • 10. http://www.slideshare.net/tylerschultz/robolectric- android-unit-testing-framework from 2011 Robolectric background from 2010 (more code examples, but a little dated) http://www.slideshare.net/ joemoore1/tdd-android-applications-with-robolectric
  • 11. Good Ideas in Testing • Multiple assertions per test are OK • Test only one concept per test method • You can write multiple test methods for one UI story • Don’t test other libraries’code • Look for ways to simplify your tests
  • 12. private  Solo  solo;       public  MainActivityTest()  {   super(MainActivity.class);   }       @Before   protected  void  setUp()  throws  Exception  {     super.setUp();     solo  =  new  Solo(getInstrumentation(),  getActivity());   }   ! @Test   public  void  testFBFailedLoginReturnsToErrorView()  {     MainActivity  activity  =  getActivity();     int  errorResultCode  =  0;     int  fakeRequestCode  =  64208;     activity.onActivityResult(fakeRequestCode,  errorResultCode,         new  Intent());   !   TextView  tvError  =  (TextView)     activity.findViewById(R.id.tv_login_error);     String  text  =  (String)  tvError.getText();     assertThat(text,  equalTo(activity.getResources().               getString(R.string.txt_login_error)));   }
  • 14. Building with Tests The goal of test coverage is to avoid manual work. How do you run automated tests? Continuous integration! You rang, sir?
  • 15. Your Basic CI Setup Write tests in your IDE Commit projects to a build server Run build scripts Deploy tested .apk as dev build Eclipse, Android Studio Jenkins with Git hooks Jenkins Hockey, XL Studio Details on the CodePath wiki! https://github.com/thecodepath/android_guides/wiki/ Building-Gradle-Projects-with-Jenkins-CI
  • 16. Using Gradle? • Running CI with Gradle, you can configure build.gradle to run your Robolectric and your JUnit tests • Develop locally in Android Studio • Run tests with • Then push the dev configuration to your CI environment’s build.gradle file You really should… gradle build http://blog.blundell-apps.com/android-gradle-app-with- robolectric-junit-tests/
  • 17. Set up deployment tool to distribute .apk (XL Studio or HockeyApp) Setup Flow Write a build script that sends .apk from Jenkins to deployment tool Configure Jenkins to: ! Write test projects1 2 3 4 1. run test projects as part of build 2. start a new build whenever you push code
  • 18. Your Day-to-Day Write tests and features Push code to repo Jenkins runs the test projects as part of the .apk build Nope Yup New .apk gets sent out to deployment tool Read Jenkins logs Try, try again Trigger Jenkins Build succeeded? Tests passed?
  • 19. Robotium in CI? • Configure Jenkins to launch an emulator • Use the Android Emulator Plugin
  • 20. • Big thanks to Nathan & Tim • Contribute to the CodePath wiki! ! • Stay in touch? • Also, we’re hiring. https://github.com/thecodepath/android_guides and @tensoryalacenski@gmail.com ari@mangohealth.com