SlideShare a Scribd company logo
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

More Related Content

PDF
Amplify - TDD on Android with Robolectric
PPTX
Android Functional UI Testing at Amplify
PPTX
Robolectric v2
PPTX
Different Android Test Automation Frameworks - What Works You the Best?
PPTX
Mobile App Penetration Testing Bsides312
PDF
Android's Warp Pipe
PPTX
Selendroid in Action
PPTX
React Native Masterclass
Amplify - TDD on Android with Robolectric
Android Functional UI Testing at Amplify
Robolectric v2
Different Android Test Automation Frameworks - What Works You the Best?
Mobile App Penetration Testing Bsides312
Android's Warp Pipe
Selendroid in Action
React Native Masterclass

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

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

More from Peter Friese (20)

PDF
Building Reusable SwiftUI Components
PDF
Firebase & SwiftUI Workshop
PDF
Building Reusable SwiftUI Components
PDF
Firebase for Apple Developers - SwiftHeroes
PDF
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
PDF
async/await in Swift
PDF
Firebase for Apple Developers
PDF
Building Apps with SwiftUI and Firebase
PDF
Rapid Application Development with SwiftUI and Firebase
PDF
Rapid Application Development with SwiftUI and Firebase
PDF
6 Things You Didn't Know About Firebase Auth
PDF
Five Things You Didn't Know About Firebase Auth
PDF
Building High-Quality Apps for Google Assistant
PDF
Building Conversational Experiences with Actions on Google
PDF
Building Conversational Experiences with Actions on Google
PDF
What's new in Android Wear 2.0
PDF
Google Fit, Android Wear & Xamarin
PDF
Introduction to Android Wear
PDF
Google Play Services Rock
PDF
Introduction to Android Wear
Building Reusable SwiftUI Components
Firebase & SwiftUI Workshop
Building Reusable SwiftUI Components
Firebase for Apple Developers - SwiftHeroes
 +  = ❤️ (Firebase for Apple Developers) at Swift Leeds
async/await in Swift
Firebase for Apple Developers
Building Apps with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
Rapid Application Development with SwiftUI and Firebase
6 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 Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
What's new in Android Wear 2.0
Google Fit, Android Wear & Xamarin
Introduction to Android Wear
Google Play Services Rock
Introduction to Android Wear
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Dropbox Q2 2025 Financial Results & Investor Presentation
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Monthly Chronicles - July 2025
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

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