SlideShare a Scribd company logo
iOS Unit Testing Like a Boss
Matt Darnall, Salesforce
@mdarnall
Safe harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any
litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our
service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to
larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these
forward-looking statements.
Who
Is this
Guy?
Objective-C developers have, for the
most part, remained relatively
apathetic to Unit Testing ("There's
that SenTest thing, but who uses
that, really?").
-Matt Thompson
NSHipster.com
“.. I don't think we have a problem with
tools. We have a cultural problem that
we need to fix, and that's something only
we (you and me) can do something
about. Go and spread the word”
-Luis Solano
Nocilla Project
Testing doesn’t have
to be an afterthought
Stand On The
Shoulders Of
Giants
Use tools that support
developer efficiency
and happiness
My
Testing
Tools

✓ Specta /
Expecta
✓ OCMock
✓ OHHTTPStubs
✓ AppCode
✓ XCTool
Specta

✓ Fluent style
similar to RSpec,
Mocha, etc.
✓ Lightweight and
easy to setup
✓ Asynchronous
Testing
Expecta

✓ Similar to
RSpec
Matchers
✓ Easy to read
✓ Framework
agnostic
OCMoc
k

✓
✓
✓
✓

Stubs
Mocks
Partial Mocks
Protocol
Mocks
AppCod
e

✓ Refactorings
✓ Code analysis
✓ Better
navigation of
projects
XCTool

✓ Tool for builds
and tests at the
command line
✓ Better support for
Continuous
Integration
Find the tools that
help you
be productive and
efficient
The Magic Tricks
of Testing
Sandi Metz
Programmer, Author, Speaker
Good
Tests
Are

✓ Thorou
gh
✓ Stable
✓ Fast
Focus on messages
Incoming

Object Under Test

Sent To
Self

Outgoing
Message Types
Queries: Return something, change
nothing
Commands: Return nothing, change
something
iOS Unit Testing Like a Boss
Rule #1
Test incoming query messages
by making assertions
about what they send back
iOS Unit Testing Like a Boss
Rule #2

Test incoming command
messages
by making assertions
about direct public side effects
iOS Unit Testing Like a Boss
Rule #3
Do not test private methods
Do not make assertions about their
result
Do not expect to send them
iOS Unit Testing Like a Boss
Rule #4
Do not test outgoing query messages
Do not make assertions about their
result
Do not expect to send them
iOS Unit Testing Like a Boss
Rule #5
Expect to send
outgoing command messages
iOS Unit Testing Like a Boss
GitHub Trending Repositories
Magic Tricks Applied to
iOS
Incoming Query
Message
numberOfRowsInSection:

UITableViewDataSource
cellForRowAtIndexPath:

Incoming
Queries

make assertions
about what is sent back
Incoming Command
Message
ViewController

view

Incoming Command

make assertions
about direct public side
effects
Testing Outlets &
1

Actions
Test that outlets exist

2 Test that outlets contain actions back to
methods on the controller
3 Send the action command to the
ViewController and assert any public side
effects.
Incoming Command & Outgoing
Query
viewWillAppear

Incoming
Command

ViewController

GithubSearchClient

getTrendingRepositories

Outgoing
Query

Incoming
Query

Do not test outgoing query messages
Do not make assertions about their result
Do not expect to send them
Stub the outgoing query
message
ViewController
getTrendingRepositories

Test Double

Outgoing
Query

Stubs provide “canned” answers
to calls made during the test
Dependency
Injection
initWithSearchClient

ViewController

✓ Pass dependencies to initializer (aka Constructor
Injection)
✓ Set dependencies with properties (aka Setter
injection)
Outgoing
Commands
Model

postNotification

Outgoing
Command

Expect to send
outgoing command
messages

NSNotificationCenter
Outgoing
Commands
ViewController

addObserver

Outgoing
Command

Expect to send
outgoing command
messages

NSNotificationCenter
More!

✓

Follow on Chatter

✓

http://http://bit.lyhttp://bit.ly/http:
//bit.ly/HvRbZQ

✓

http://http://mdarnall.com

✓

Get Involved!
✓

Thanks!
Sandi Metz

✓

The maintainers of these
awesome projects
Matt Darnall

@mdarnall
mdarnall.com
iOS Unit Testing Like a Boss

More Related Content

PDF
Advanced Testing and Debugging using the Developer Console webinar
PPTX
Continuous Integration In The Cloud Final (1)
PPTX
Apex for Admins: Beyond the Basics
PDF
Team Development on Force.com with Github and Ant
PDF
EVOLVE'15 | Enhance | Rene Ugarte | AEM Quality Assurance
PPTX
Deep Dive into Apex Triggers
PDF
Integration Testing in AEM
PPT
Test Automation With Cucumber JVM, Selenium, and Mocha
Advanced Testing and Debugging using the Developer Console webinar
Continuous Integration In The Cloud Final (1)
Apex for Admins: Beyond the Basics
Team Development on Force.com with Github and Ant
EVOLVE'15 | Enhance | Rene Ugarte | AEM Quality Assurance
Deep Dive into Apex Triggers
Integration Testing in AEM
Test Automation With Cucumber JVM, Selenium, and Mocha

What's hot (20)

PPTX
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
PDF
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
PPTX
Story Testing Approach for Enterprise Applications using Selenium Framework
PDF
Coding Together - A Dev Workflow
PPTX
An easy way to automate complex UI
PPTX
Jenkins as the Test Reporting Framework
PPTX
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
PPTX
Roman iovlev battle - JDI vs Selenide - Selenium Camp
PPTX
Visual Studio ALM 2013 - Edition Comparison
PDF
Testing Salesforce at Cloud Scale
PDF
Unstoppable releases with kanban
PPTX
How to scale your Test Automation
PPTX
Test Automation
PPTX
How to Add Test Automation to your Quality Assurance Toolbelt
PPTX
Test Automation Architecture in Microservices
PPTX
Test automation project estimation calculator
PDF
Apex Testing Best Practices
PPTX
Agile test-management-test-rail-lastest
PDF
Get Started with JMeter in 60 Minutes
PPTX
Colorful world-of-visual-automation-testing-latest
Salesforce Meetup 18 April 2015 - Apex Trigger & Scheduler Framworks
DevOps - Agile on Steroids by Tom Clement Oketch and Augustine Kisitu
Story Testing Approach for Enterprise Applications using Selenium Framework
Coding Together - A Dev Workflow
An easy way to automate complex UI
Jenkins as the Test Reporting Framework
Reaching for Your Quality Stretch Goals: Testing at Realtor.com
Roman iovlev battle - JDI vs Selenide - Selenium Camp
Visual Studio ALM 2013 - Edition Comparison
Testing Salesforce at Cloud Scale
Unstoppable releases with kanban
How to scale your Test Automation
Test Automation
How to Add Test Automation to your Quality Assurance Toolbelt
Test Automation Architecture in Microservices
Test automation project estimation calculator
Apex Testing Best Practices
Agile test-management-test-rail-lastest
Get Started with JMeter in 60 Minutes
Colorful world-of-visual-automation-testing-latest
Ad

Viewers also liked (20)

PDF
Mocking In Swift
PDF
iOS Test-Driven Development
PDF
How To Build iOS Apps Without interface Builder
PDF
Tdd
PDF
Automated UI testing for iOS apps using KIF framework and Swift
PPTX
UNIT TESTING PPT
PPT
Unit Testing in iOS
KEY
iOS Unit Testing
PDF
Tech Talk #5 : KIF-iOS Integration Testing Framework - Nguyễn Hiệp
PDF
Kotlin, Spek and tests
PDF
Component-driven UIs - Mobile Era 2016
PDF
Swift testing ftw
PDF
Unit testing in swift 2 - The before & after story
PDF
Testing iOS10 Apps with Appium and its new XCUITest backend
PPTX
Protocol-Oriented Programming in Swift
PDF
Testing in swift
PPT
Generating test cases using UML Communication Diagram
PPTX
Unit Testing in Swift
PDF
7 Stages of Unit Testing in iOS
PDF
iOS advanced architecture workshop 3h edition
Mocking In Swift
iOS Test-Driven Development
How To Build iOS Apps Without interface Builder
Tdd
Automated UI testing for iOS apps using KIF framework and Swift
UNIT TESTING PPT
Unit Testing in iOS
iOS Unit Testing
Tech Talk #5 : KIF-iOS Integration Testing Framework - Nguyễn Hiệp
Kotlin, Spek and tests
Component-driven UIs - Mobile Era 2016
Swift testing ftw
Unit testing in swift 2 - The before & after story
Testing iOS10 Apps with Appium and its new XCUITest backend
Protocol-Oriented Programming in Swift
Testing in swift
Generating test cases using UML Communication Diagram
Unit Testing in Swift
7 Stages of Unit Testing in iOS
iOS advanced architecture workshop 3h edition
Ad

Similar to iOS Unit Testing Like a Boss (20)

PDF
codeLive: Positive and negative testing
PDF
Introduction to Apex Triggers
PPTX
Apex 10 commandments df14
PDF
Gesture Controlled Interactions with Platform Events and IoT Explorer
PDF
CodeLive with Cynthia Thomas - Refactoring data dependent code.
PDF
Build Together And Deliver Continuously With Salesforce DX
PDF
Building Mobile Apps That Deliver Salesforce to Your Employees
PDF
Easy No-Code Integrations with External Services and Visual Flow
PPTX
CCT London 2013 Theatre Intro to Apex
PDF
Five Developer Tips Every Admin Needs To Know
PPTX
2016 SUTOL - Salesforce App Cloud and Domino - same same, but different
PDF
Manage Development in Your Org with Salesforce Governance Framework
PDF
Understanding Complex Data Trends in Salesforce1 Objects Using Heroku
PDF
Introduction to Apex Triggers
PPTX
Salesforce at Continuous Delivery Foundation Summit
PPTX
2016 ISBG - Salesforce App Cloud and Domino - same same, but different
PDF
Fremont Salesforce Community Group - Salesforce Labs Day - Flow Templates
PDF
Einstein Analytics for Developers
PPTX
Successfully Scaling an Agile Innovation Culture with Perforce - 2011 Perforc...
PPTX
Force.com Friday - Intro to Force.com
codeLive: Positive and negative testing
Introduction to Apex Triggers
Apex 10 commandments df14
Gesture Controlled Interactions with Platform Events and IoT Explorer
CodeLive with Cynthia Thomas - Refactoring data dependent code.
Build Together And Deliver Continuously With Salesforce DX
Building Mobile Apps That Deliver Salesforce to Your Employees
Easy No-Code Integrations with External Services and Visual Flow
CCT London 2013 Theatre Intro to Apex
Five Developer Tips Every Admin Needs To Know
2016 SUTOL - Salesforce App Cloud and Domino - same same, but different
Manage Development in Your Org with Salesforce Governance Framework
Understanding Complex Data Trends in Salesforce1 Objects Using Heroku
Introduction to Apex Triggers
Salesforce at Continuous Delivery Foundation Summit
2016 ISBG - Salesforce App Cloud and Domino - same same, but different
Fremont Salesforce Community Group - Salesforce Labs Day - Flow Templates
Einstein Analytics for Developers
Successfully Scaling an Agile Innovation Culture with Perforce - 2011 Perforc...
Force.com Friday - Intro to Force.com

More from Salesforce Developers (20)

PDF
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
PDF
Maximizing Salesforce Lightning Experience and Lightning Component Performance
PDF
Local development with Open Source Base Components
PPTX
TrailheaDX India : Developer Highlights
PDF
Why developers shouldn’t miss TrailheaDX India
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
PPTX
CodeLive: Converting Aura Components to Lightning Web Components
PPTX
Enterprise-grade UI with open source Lightning Web Components
PPTX
TrailheaDX and Summer '19: Developer Highlights
PDF
Live coding with LWC
PDF
Lightning web components - Episode 4 : Security and Testing
PDF
LWC Episode 3- Component Communication and Aura Interoperability
PDF
Lightning web components episode 2- work with salesforce data
PDF
Lightning web components - Episode 1 - An Introduction
PDF
Migrating CPQ to Advanced Calculator and JSQCP
PDF
Scale with Large Data Volumes and Big Objects in Salesforce
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
PDF
Modern Development with Salesforce DX
PDF
Get Into Lightning Flow Development
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Local development with Open Source Base Components
TrailheaDX India : Developer Highlights
Why developers shouldn’t miss TrailheaDX India
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Converting Aura Components to Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
TrailheaDX and Summer '19: Developer Highlights
Live coding with LWC
Lightning web components - Episode 4 : Security and Testing
LWC Episode 3- Component Communication and Aura Interoperability
Lightning web components episode 2- work with salesforce data
Lightning web components - Episode 1 - An Introduction
Migrating CPQ to Advanced Calculator and JSQCP
Scale with Large Data Volumes and Big Objects in Salesforce
Replicate Salesforce Data in Real Time with Change Data Capture
Modern Development with Salesforce DX
Get Into Lightning Flow Development
Integrate CMS Content Into Lightning Communities with CMS Connect

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Programs and apps: productivity, graphics, security and other tools
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...

iOS Unit Testing Like a Boss