SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Bring Back the Fun to
Testing Android Apps
with Robolectric

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Bring Back the Fun to
Testing Android Apps
with Robolectric

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Testing Android Apps with Robolectric

What’s the problem?
Why is Robolectric a solution?
Demo
Peter Friese - @peterfriese - http:/
/www.peterfriese.de
What’s the problem?

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
What’s the problem?
Running tests requires:
•

Dexing Dexing

•

Packaging Packaging

•

Installation on device / emulator Installation

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Dexing

Packaging

Peter Friese - @peterfriese - http:/
/www.peterfriese.de

Installation
Robolectric to the rescue!
Run tests in a regular JVM, not on Dalvik VM
•

Dexing

•

Packaging

•

Installation on device / emulator

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
There is another problem…

protected void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Robolectric Solution:
Shadow Objects
•

Intercept class loading

•

Rewrite method bodies (using ASM)

•

Intercept calls to Android classes, record state
in shadow classes

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
FEST - Readability for Your Tests
Plain JUnit:
assertEquals(View.GONE, textView.getVisibility());
!
java.lang.AssertionError: expected:<8> but was:<0>

FEST:
assertThat(textView).isGone();
!
java.lang.AssertionError: Expected to be gone but was visible

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Demo
See http:/
/www.peterfriese.de/unit-testing-android-apps-with-robolectric-and-eclipse/ for a
step-by-step description of how to set up Robolectric in Eclipse

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Electrified? Here’s where to get Robolectric / FEST

Web: http:/
/ww.robolectric.org
Github: https:/
/github.com/robolectric/robolectric

Peter Friese - @peterfriese - http:/
/www.peterfriese.de

Web: http:/
/square.github.io/fest-android/
Github: https:/
/github.com/square/fest-android
Contact

Peter Friese



ter.friese@zuhlke.com
pe
!
td

Zuhlke Engineering L
43 Whitfield St

London

W1T 4HD

!
+44 7825 688 244

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
Image credits

•

Snail - http:/
/www.wallsfeed.com/snail-journey-leaf/

Peter Friese - @peterfriese - http:/
/www.peterfriese.de
The End

Más contenido relacionado

Similar a Bring Back the Fun to Testing Android Apps with Robolectric

AtlasCamp 2013: Bring your own Stack
AtlasCamp 2013: Bring your own Stack AtlasCamp 2013: Bring your own Stack
AtlasCamp 2013: Bring your own Stack
colleenfry
 
Vim Plugin Deployment
Vim Plugin DeploymentVim Plugin Deployment
Vim Plugin Deployment
偉格 高
 
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devicesUPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
Lis Pardi
 

Similar a Bring Back the Fun to Testing Android Apps with Robolectric (20)

Selenium IDE and Beyond
Selenium IDE and BeyondSelenium IDE and Beyond
Selenium IDE and Beyond
 
Hands on React Native: From Zero to Hero
Hands on React  Native:  From Zero to HeroHands on React  Native:  From Zero to Hero
Hands on React Native: From Zero to Hero
 
Hands-on React Native: From Zero to Hero
Hands-on React Native: From Zero to HeroHands-on React Native: From Zero to Hero
Hands-on React Native: From Zero to Hero
 
The First Wave of IoT—Blood in the Water
The First Wave of IoT—Blood in the WaterThe First Wave of IoT—Blood in the Water
The First Wave of IoT—Blood in the Water
 
Simplifying your test runs with „Make“
Simplifying your test runs with „Make“Simplifying your test runs with „Make“
Simplifying your test runs with „Make“
 
Discover Android Wear
Discover Android WearDiscover Android Wear
Discover Android Wear
 
44CON 2014 - Researching Android Device Security with the Help of a Droid Arm...
44CON 2014 - Researching Android Device Security with the Help of a Droid Arm...44CON 2014 - Researching Android Device Security with the Help of a Droid Arm...
44CON 2014 - Researching Android Device Security with the Help of a Droid Arm...
 
Use Scrum and Continuous Delivery to innovate like crazy!
Use Scrum and Continuous Delivery to innovate like crazy!Use Scrum and Continuous Delivery to innovate like crazy!
Use Scrum and Continuous Delivery to innovate like crazy!
 
Webinar on How to use MyAppConverter
Webinar on How to use  MyAppConverterWebinar on How to use  MyAppConverter
Webinar on How to use MyAppConverter
 
Basic iPad Training Session for VIU Forestry Students
Basic iPad Training Session for VIU Forestry StudentsBasic iPad Training Session for VIU Forestry Students
Basic iPad Training Session for VIU Forestry Students
 
AtlasCamp 2013: Bring your own Stack
AtlasCamp 2013: Bring your own Stack AtlasCamp 2013: Bring your own Stack
AtlasCamp 2013: Bring your own Stack
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Rewrite or Refactor That Is the Question - DecompileD 2021
Rewrite or Refactor That Is the Question - DecompileD 2021Rewrite or Refactor That Is the Question - DecompileD 2021
Rewrite or Refactor That Is the Question - DecompileD 2021
 
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzieHey You Got Your TDD in my SQL DB by Jeff McKenzie
Hey You Got Your TDD in my SQL DB by Jeff McKenzie
 
Continuous Delivery & DevOps in the Enterprise
Continuous Delivery & DevOps in the EnterpriseContinuous Delivery & DevOps in the Enterprise
Continuous Delivery & DevOps in the Enterprise
 
Continuous Integration, the minimum viable product
Continuous Integration, the minimum viable productContinuous Integration, the minimum viable product
Continuous Integration, the minimum viable product
 
Vim Plugin Deployment
Vim Plugin DeploymentVim Plugin Deployment
Vim Plugin Deployment
 
selenium-2-mobile-web-testing
selenium-2-mobile-web-testingselenium-2-mobile-web-testing
selenium-2-mobile-web-testing
 
Getting started with Octopus Deploy
Getting started with Octopus DeployGetting started with Octopus Deploy
Getting started with Octopus Deploy
 
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devicesUPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
UPA Boston 2012: My iPhone or Yours? Usability testing on mobile devices
 

Más de Peter Friese

Más de Peter Friese (20)

Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase & SwiftUI Workshop
Firebase & SwiftUI WorkshopFirebase & SwiftUI Workshop
Firebase & SwiftUI Workshop
 
Building Reusable SwiftUI Components
Building Reusable SwiftUI ComponentsBuilding Reusable SwiftUI Components
Building Reusable SwiftUI Components
 
Firebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroesFirebase for Apple Developers - SwiftHeroes
Firebase for Apple Developers - SwiftHeroes
 
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Firebase for Apple Developers
Firebase for Apple DevelopersFirebase for Apple Developers
Firebase for Apple Developers
 
Building Apps with SwiftUI and Firebase
Building Apps with SwiftUI and FirebaseBuilding Apps with SwiftUI and Firebase
Building Apps with SwiftUI and Firebase
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and FirebaseRapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
 
6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth
 
Five Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase AuthFive Things You Didn't Know About Firebase Auth
Five Things You Didn't Know About Firebase Auth
 
Building High-Quality Apps for Google Assistant
Building High-Quality Apps for Google AssistantBuilding High-Quality Apps for Google Assistant
Building High-Quality Apps for Google Assistant
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on GoogleBuilding Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
What's new in Android Wear 2.0
What's new in Android Wear 2.0What's new in Android Wear 2.0
What's new in Android Wear 2.0
 
Google Fit, Android Wear & Xamarin
Google Fit, Android Wear & XamarinGoogle Fit, Android Wear & Xamarin
Google Fit, Android Wear & Xamarin
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Bring Back the Fun to Testing Android Apps with Robolectric

  • 1. Bring Back the Fun to Testing Android Apps with Robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 2. Bring Back the Fun to Testing Android Apps with Robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 3. Testing Android Apps with Robolectric What’s the problem? Why is Robolectric a solution? Demo Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 4. What’s the problem? Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 5. What’s the problem? Running tests requires: • Dexing Dexing • Packaging Packaging • Installation on device / emulator Installation Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 6. Dexing Packaging Peter Friese - @peterfriese - http:/ /www.peterfriese.de Installation
  • 7. Robolectric to the rescue! Run tests in a regular JVM, not on Dalvik VM • Dexing • Packaging • Installation on device / emulator Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 8. There is another problem… protected void onCreate(Bundle savedInstanceState) { throw new RuntimeException("Stub!"); } Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 9. Robolectric Solution: Shadow Objects • Intercept class loading • Rewrite method bodies (using ASM) • Intercept calls to Android classes, record state in shadow classes Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 10. FEST - Readability for Your Tests Plain JUnit: assertEquals(View.GONE, textView.getVisibility()); ! java.lang.AssertionError: expected:<8> but was:<0> FEST: assertThat(textView).isGone(); ! java.lang.AssertionError: Expected to be gone but was visible Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 11. Demo See http:/ /www.peterfriese.de/unit-testing-android-apps-with-robolectric-and-eclipse/ for a step-by-step description of how to set up Robolectric in Eclipse Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 12. Electrified? Here’s where to get Robolectric / FEST Web: http:/ /ww.robolectric.org Github: https:/ /github.com/robolectric/robolectric Peter Friese - @peterfriese - http:/ /www.peterfriese.de Web: http:/ /square.github.io/fest-android/ Github: https:/ /github.com/square/fest-android
  • 13. Contact Peter Friese ter.friese@zuhlke.com pe ! td Zuhlke Engineering L 43 Whitfield St London W1T 4HD ! +44 7825 688 244 Peter Friese - @peterfriese - http:/ /www.peterfriese.de
  • 14. Image credits • Snail - http:/ /www.wallsfeed.com/snail-journey-leaf/ Peter Friese - @peterfriese - http:/ /www.peterfriese.de