SlideShare a Scribd company logo
Android TDD
January 25, 2012
Chuck Greb
@ecgreb
Why Test?
Validate Requirements
Ensure Quality
Reduce Cost
Why Unit Test?
Test smallest possible units of code
(in isolation)
Makes refactoring easier
(regression suite)
Self-documenting code
Fakes
Mocks
Stubs
Why TDD?
(Test-Driven Development)
Improves Architecture
Reduced debugging time
Red -> Green -> Refactor
Tests must be fast!
Other kinds of tests?
Inverted Testing Pyramid
(Un-Inverted) Testing Pyramid
QA Job Security
Unit
Testing is
Awesome!!
Testing Approaches
● F@#% It!
● Manual
● Monkey Testing
● Android Testing Framework
● JUnit 4 + POJOs
● Robolectric
● Custom
Testing Approaches
● F@#% It!
● Manual
● Monkey Testing
● Android Testing Framework
● JUnit 4 + POJOs
● Robolectric
● Custom
Android Testing
Framework
JUnit 3 + Instrumentation
Android Testing Framework
Test Case Classes
● TestCase
● AndroidTestCase
● ActivityTestCase
● ActivityUnitTestCase
● ServiceTestCase
● ProviderTestCase2
● ActivityInstrumentationTestCase2
Android Mocks
HelloAndroidActivity
main.xml
StringBling
Android TDD
HelloAndroidActivityTest
Success!!!
Compile, dex, package, and install
two APKs on emulator or device
Additional Challenges
● Classes and methods declared final
● Lack of interfaces
● Non-public constructors
● Static methods
JUnit 4 + POJOs
HelloAndroidActivityJUnitTest
Android TDD
StringBling
StringBlingTest
Success!!!
But we want to test
ALL our code
Robolectric
Robolectric
Test-Drive Your Android Code
Shadow ObjectsShadow Objects
Shadow Objects in Action
View and Resource Loading
HelloAndroidActivityRobolectricTest
Success!!!
More fun with Shadows
Using ShadowImageView
Using ShadowActivity
Write your own
custom shadows
Contribute to Robolectric
Resources
● developer.android.com/guide/topics/testing
● junit.org
● pivotal.github.com/robolectric
Reading
● Robert C. Martin (Uncle Bob)
● Michael Feathers
● Kent Beck
Find your testing Zen
Chuck Greb
@ecgreb
http://ecgreb.com/blog
https://github.com/ecgreb/StringBling

More Related Content

PPTX
Unit tests 101
PDF
TDD with Ruby
KEY
Unit Testing Your Application
PDF
Testing: Heaven or Hell
PPTX
Android tdd
PDF
Android Devops : Master Continuous Integration and Delivery
PDF
Test Driven Development
PDF
MOPCON 2015 - Tips of Mobile Continuous Delivery
Unit tests 101
TDD with Ruby
Unit Testing Your Application
Testing: Heaven or Hell
Android tdd
Android Devops : Master Continuous Integration and Delivery
Test Driven Development
MOPCON 2015 - Tips of Mobile Continuous Delivery

What's hot (20)

PDF
Agile Programming Systems # TDD intro
PDF
GTAC 2015
PPTX
A Brief Introduction to Test-Driven Development
PPTX
Testing With OutSystems
PPTX
TDD Basics with Angular.js and Jasmine
PDF
Continuous inspection with Sonar
PPTX
C++ unit testing top 5 problems and solutions
PPTX
Tdd and bdd
PDF
Android Test Driven Development & Android Unit Testing
PPT
Test automation in agile ecosystem
PDF
iOS Test-Driven Development
PDF
Refactoring Legacy Code
PDF
TDD done right - tests immutable to refactor
PDF
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
PPTX
API Automation Testing Using RestAssured+Cucumber
PDF
Test Driven Development Powered by LEGO
PDF
Functional Tests Automation with Robot Framework
PDF
Amplify - TDD on Android with Robolectric
PDF
User story workflow (eng)
PPTX
Cost of defects
Agile Programming Systems # TDD intro
GTAC 2015
A Brief Introduction to Test-Driven Development
Testing With OutSystems
TDD Basics with Angular.js and Jasmine
Continuous inspection with Sonar
C++ unit testing top 5 problems and solutions
Tdd and bdd
Android Test Driven Development & Android Unit Testing
Test automation in agile ecosystem
iOS Test-Driven Development
Refactoring Legacy Code
TDD done right - tests immutable to refactor
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
API Automation Testing Using RestAssured+Cucumber
Test Driven Development Powered by LEGO
Functional Tests Automation with Robot Framework
Amplify - TDD on Android with Robolectric
User story workflow (eng)
Cost of defects
Ad

Similar to Android TDD (20)

PDF
Test driven development_continuous_integration
PDF
Test Driven Development with PHP
PDF
Testing Node.js.pdf
PPTX
The Test way
PDF
#BABBQAmsterdam The other Android getting started guide: Gradle power
PDF
Unit testing (eng)
PPTX
Understanding TDD - theory, practice, techniques and tips.
PDF
Testing on Android
PDF
Testing with Express, Mocha & Chai
PDF
Android testing
PPTX
Product quality in agile project
PDF
Drulenium - Testing Made Easy
PDF
End-end tests as first class citizens - SeleniumConf 2020
PDF
Writing Tests with the Unity Test Framework
PDF
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
PPTX
Reliable mobile test automation
PPTX
Battle for Code Quality - A Story of One Java Project
ODP
Automated Tests for Android apps
PDF
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
PPTX
NET Code Testing
Test driven development_continuous_integration
Test Driven Development with PHP
Testing Node.js.pdf
The Test way
#BABBQAmsterdam The other Android getting started guide: Gradle power
Unit testing (eng)
Understanding TDD - theory, practice, techniques and tips.
Testing on Android
Testing with Express, Mocha & Chai
Android testing
Product quality in agile project
Drulenium - Testing Made Easy
End-end tests as first class citizens - SeleniumConf 2020
Writing Tests with the Unity Test Framework
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Reliable mobile test automation
Battle for Code Quality - A Story of One Java Project
Automated Tests for Android apps
Unlocking the Power of ChatGPT and AI in Testing - NextSteps, presented by Ap...
NET Code Testing
Ad

More from Chuck Greb (13)

PDF
Testable Android Architecture
PDF
Building Location-Aware Apps with Open Source & Open Data (SXSW 2015)
PDF
PDF
What's the deal with Android maps?
PDF
Building Location-Aware Apps using Open Source (AnDevCon SF 2014)
PDF
Building Location-Aware Apps with Open Source & Open Data
PDF
Notifunk
PDF
Data to Go: Mobile API Design (SXSW)
PDF
AnDevCon 2013 Roundup
PDF
Data to Go: Mobile API Design
PDF
Data To Go: Mobile API Design (Lightning Talk)
PDF
Google Charts for native Android apps
PDF
HowAboutWe... Build an Android App
Testable Android Architecture
Building Location-Aware Apps with Open Source & Open Data (SXSW 2015)
What's the deal with Android maps?
Building Location-Aware Apps using Open Source (AnDevCon SF 2014)
Building Location-Aware Apps with Open Source & Open Data
Notifunk
Data to Go: Mobile API Design (SXSW)
AnDevCon 2013 Roundup
Data to Go: Mobile API Design
Data To Go: Mobile API Design (Lightning Talk)
Google Charts for native Android apps
HowAboutWe... Build an Android App

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding

Android TDD