SlideShare a Scribd company logo
TEST DRIVEN DEVELOPMENT
COMMON CHALLENGES & 

BEST PRACTICES FOR
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
ON IOS
COMMON PITFALLS & BEST PRACTICES FOR TDD
YOUR PRESENTER
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
4/2015~11/2015
12/2015~
1/2014~
WHY TDD?
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
T
D
D Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Question What is TDD?
TEST
DRIVEN
DEVELOPMENTTokyo iOS Meetup June 2016Derek Lee @derekleerock
Question What is TDD?
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
WRITE A TEST
MAKE IT PASS
YADDA YADDA YADDA
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge Getting over the hump
TDD CRASH COURSE
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge Getting over the hump
TESTING WORKFLOW: RED → GREEN → REFACTOR
▸ Write a failing test
▸ Write the simplest implementation
to make it pass
▸ Refactor
▸ Repeat
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
▸ Compiler Errors = Failing Test
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
TESTING WORKFLOW: RED → GREEN → REFACTOR
▸ Red = Failing Test
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
TESTING WORKFLOW: RED → GREEN → REFACTOR
▸ Green = Passing Test
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
TESTING WORKFLOW: RED → GREEN → REFACTOR
TESTING WORKFLOW: RED → GREEN → REFACTOR
▸ Keyboard Shortcuts for improving your test workflow:
▸ ⌘ + 5 → Show the Xcode Test Navigator
▸ ⇧ + ⌘ + U → Compile Tests
▸ ⌘ + U → Run All Tests In Suite
▸ MAGIC + U → Run all tests for current class
▸ MAGIC + G → Re-run last test
* MAGIC = ⌃ + ⌥ + ⌘
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ Setup - Create objects needed to execute the test
▸ Action - Prod the subject (object) under test
▸ Verify - Make assertions about your expectations
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ Override setUp() and tearDown() methods as needed
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ Clearly indicate where the “Act” portion of your test is:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
▸ Use the appropriate assertion for your test expectation
(XCTest)
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
let number = 11
XCTAssertTrue(number == 12)
error: -[MyProjectTests.MyObjectTest testMethod] : XCTAssertTrue
failed -
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ Use the appropriate assertion for your test expectation
(XCTest)
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
let number = 11
XCTAssertEqual(number, 12)
error: -[MyProjectTests.MyObjectTest testMethod] : XCTAssertEqual
failed: ("Optional(11)") is not equal to ("Optional(12)") -
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ XCT Assertion Types
▸ AssertTrue, AssertFalse
▸ AssertEqual, AssertNotEqual (+WithAccuracy)
▸ AssertLessThan, AssertGreaterThan (+OrEqual)
▸ AssertNil, AssertNotNil
▸ AssertThrowsError
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
▸ Nimble (Matcher Framework)
▸ expect(~).to(~) or expect(~).toNot(~)
▸ expect(~).to(beTrue()) or expect(~).to(beFalse())
▸ expect(~).to(beLessThan(~)) // greaterThan…
▸ expect(~).to(beAKindOf(~))
▸ Can also write custom matchers with Nimble
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
GOLDEN RULES OF TDD
▸ Test First
▸ Simplest Solution
▸ Test Once
▸ Test in Isolation
▸ Test the interface, not the implementation
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
TDD BEST PRACTICES
▸ One Failing Test at a Time
▸ Create a Test List
▸ Assert First
▸ Simplest Test Data / Evident Test Data
▸ Avoid conditionals and loops
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
CLASSIC
▸ “Detroit” or “Chicago”
▸ Prefers real objects
▸ Focus: Algorithms
▸ State verification
▸ Test doubles as needed
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
MOCKIST
▸ “London”
▸ Prefers mocks
▸ Focus: Object Interactions
▸ Behavior verification
▸ Test doubles always
GETTING OVER THE HUMP
CONTINUOUS INTEGRATION
▸ Build and test in a clean environment
▸ Automation of your test suite
▸ Test across OSs, simulators, devices
▸ Xcode Server, TeamCity, Travis, CircleCI, Jenkins…
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
CONTINUOUS INTEGRATION - XCODE SERVER BIG SCREEN
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
CONTINUOUS INTEGRATION - PIVOTAL PROJECT MONITOR
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
TAKING THE BLUE PILL
▸ BDD
▸ Clean Architecture
▸ SOLID Principles: SRP, Open/Closed, LSP, ISP, DIP
▸ Don’t Repeat Yourself
▸ Just In Time Design
▸ Refactoring
▸ Continuous Integration
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
GETTING OVER THE HUMP
MY TESTS TAKE
FOREVER TO RUN
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge The Time-Consuming Test Run
THE TIME-CONSUMING TEST RUN
THE USUAL SUSPECTS
▸ Imbalanced Test Suite
▸ Testing Against External Resources
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
TESTING ICE-CREAM CONE ANTI-PATTERN
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
TESTING ICE-CREAM CONE ANTI-PATTERN
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
▸ Brittle
▸ Expensive to write/maintain
▸ Time consuming to run
UI & MANUAL TESTS CAN BE…
TESTING PYRAMID
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
]
]
ARE WE
BUILDING
THE RIGHT
SYSTEM?
ARE WE
BUILDING
THE SYSTEM
RIGHT?
TESTING PYRAMID
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
TIMETOTESTINCREASES
THE TIME-CONSUMING TEST RUN
DESIRED TEST SUITE QUALITIES FOR QUICK TEST FEEDBACK
▸ Few
▸ Fast
▸ Stable
▸ Thorough
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
WHEN TO RUN TESTS
▸ Current Unit/Feature → While building an object / feature
▸ All Units + All Feature → Before commit / push; after
pulling updates from a repo;
▸ Integration, UI → CI Suite
▸ Manual → As needed
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
WHEN TO RUN TESTS
▸ Create a target for each suite of tests that you want to run
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
WHEN TO RUN TESTS
▸ Configure scheme(s) to execute tests:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
WHEN TO RUN TESTS
▸ Use a makefile with xcodebuild (or xctool) to execute the
tests when you need to or from CI:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
units:
@xcodebuild -project Osusume.xcodeproj -scheme "Osusume" -sdk
iphonesimulator -destination "platform=iOS Simulator,OS=9.3,name=
iPhone 6" build test
integration:
@xcodebuild -project Osusume.xcodeproj -scheme "Osusume-Staging"
-sdk iphonesimulator -destination "platform=iOS Simulator,OS=9.3,
name=iPhone 6" build test
THE TIME-CONSUMING TEST RUN
GUIDANCE ON UNIT TESTING - HOW/WHAT TO TEST
▸ Sandi Metz Rails Conf 2013 “The Magic Tricks of Testing”
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
DO MY TESTS HIT EXTERNAL DEPENDENCIES?
▸ Network, REST APIs
▸ Database (includes Core Data!)
▸ File System
▸ External Library or API
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
THEN HOW TO TEST EXTERNAL DEPENDENCIES?
▸ Find the seams where communication occurs
▸ Confirm expected interactions using mock objects
▸ Create an integration test if needed
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE TIME-CONSUMING TEST RUN
GUIDANCE ON MOCK OBJECTS
▸ Martin Fowler, “Mocks Aren’t Stubs”
http://martinfowler.com/articles/mocksArentStubs.html
▸ Uncle Bob, “The Little Mocker” Blog Post
https://blog.8thlight.com/uncle-bob/2014/05/14/
TheLittleMocker.html
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
MY TEST SUITE
FEELS UNSTABLE
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge The Brittle Test Suite
THE BRITTLE TEST SUITE
THE USUAL SUSPECTS
▸ Highly-coupled objects
▸ Long, complicated, or unreadable tests
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE BRITTLE TEST SUITE
HIGHLY COUPLED OBJECTS - DESIGN & ARCHITECTURE
▸ TDD encourages us to write loosely coupled components
that can be easily tested in isolation and combined later.
▸ May need to revisit your architecture
▸ “Build & Swap”
▸ Too difficult or too costly to refactor?
▸ TDD a new component and swap it in
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE BRITTLE TEST SUITE
BUILD & SWAP EXAMPLE #1 - DRUM APP NAVIGATION UX
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE BRITTLE TEST SUITE
BUILD & SWAP EXAMPLE #2 - MIKADO REFACTOR
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
▸ Parse Integration Before:
▸ One single “God” object singleton: ParseHelper.h/.m
▸ Included in 25 other classes
▸ Parse Integration After:
▸ 4 Dependency-Injected Testable “Repository” objects
▸ Can move each repository over as needed
THE BRITTLE TEST SUITE
HOW TDD HELPS
▸ Design
▸ Loosely coupled objects
▸ Well thought out public object APIs
▸ Dev
▸ Gives immediate feedback on quality
▸ Refactoring confidence
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
THE BRITTLE TEST SUITE
HOW TO APPROACH
▸ Practice, practice, practice
▸ Reference Materials
▸ Read “Refactoring: Improving the Design of Existing
Code” (Martin Fowler)
▸ Read “Working Effectively With Legacy Code” (Michael
Feathers)
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
I DON’T KNOW
HOW TO TEST X
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge Fear of the Unknown
FEAR OF THE UNKNOWN
THE USUAL SUSPECTS
▸ What to test - what not to test
▸ How to test specific objects, dependencies, scenarios
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
KNOWING WHAT NOT TO TEST
▸ Private Methods (this is an implementation detail!)
▸ UI Design (fonts, colors, positions, constraints)
▸ Configuration Details (supporting data)
▸ Auto-generated code
▸ Test Fixtures, Test Doubles
▸ Reference: https://blog.8thlight.com/uncle-bob/
2014/04/30/When-tdd-does-not-work.html
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… VIEW CONTROLLERS
▸ Move logic out of MegaController (*Andy Matuschak -
https://realm.io/news/andy-matuschak-refactor-mega-
controller/)
▸ Using Storyboards:
▸ Property Dependency Injection
▸ Without Storyboards:
▸ Constructor Dependency Injection
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… CORE DATA
▸ Use an in-memory Core Data Store
▸ Only setup data needed for test
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… UITABLEVIEW / UICOLLECTIONVIEW
▸ Extract Datasource and/or Delegate to external object for
easier testing
▸ Leverage blocks / closures for common logic
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Swift: Mocks in Swift via Protocols (Blog post, Eli Perkins)
http://blog.eliperkins.me/mocks-in-swift-via-protocols
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
For Objective-C, see OCMock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Find the method definition(s) on the object that you need
to confirm interactions with:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Create your own protocol definition to duplicate the
method you want to confirm interaction with:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Create a fake object (spy) that implements that protocol:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Write your test:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Write the implementation:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
FEAR OF THE UNKNOWN
HOW TO TEST… NSUSERDEFAULTS
▸ Pass in the real object for production code:
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
EASY TO FALL BACK
TO OLD HABITS
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
Challenge Commitment
COMMITMENT
THE USUAL SUSPECTS
▸ Frustration, Fatigue
▸ Cutting corners
▸ Falling back to what is most comfortable
▸ Test last or not testing at all
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
TOOLS YOU’LL NEED
▸ Focus
▸ Patience
▸ Tenacity
▸ Discipline
▸ Dedication
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
COMMITMENT
TIME MANAGEMENT
HOW TO APPROACH
▸ Start Small
▸ 1% each day
▸ Think long-term: Investing in the future of your software
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
REWARDS OF STICKING TO IT
▸ Making forward progress in small increments
▸ Allows refactoring to take place with confidence
▸ Identify bugs early and avoid regressions
▸ Reduces costs up-front
▸ Add new features knowing you won’t break existing ones
▸ Deploy anytime with confidence
▸ Easier to understand code for you and your team
Tokyo iOS Meetup June 2016Derek Lee @derekleerock
COMMITMENT
@DEREKLEEROCK
Thank you!
Tokyo iOS Meetup June 2016Derek Lee @derekleerock

More Related Content

What's hot

Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
CodeOps Technologies LLP
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
nedirtv
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sachithra Gayan
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
Brian Rasmussen
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!
Kaizenko
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
Pablo Villar
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Tung Nguyen Thanh
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
Dionatan default
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
John Blum
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
Naresh Jain
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
Pablo Villar
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
harinderpisces
 
Test driven development
Test driven developmentTest driven development
Test driven development
Nascenia IT
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
satya sudheer
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
Seb Rose
 

What's hot (20)

Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 
TDD That Was Easy!
TDD   That Was Easy!TDD   That Was Easy!
TDD That Was Easy!
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
Unit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking SkeletonUnit Testing, TDD and the Walking Skeleton
Unit Testing, TDD and the Walking Skeleton
 

Viewers also liked

Writing Clean Code in Swift
Writing Clean Code in SwiftWriting Clean Code in Swift
Writing Clean Code in Swift
Derek Lee Boire
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
Derek Lee Boire
 
Standing the Test of Time: The Date Provider Pattern
Standing the Test of Time: The Date Provider PatternStanding the Test of Time: The Date Provider Pattern
Standing the Test of Time: The Date Provider Pattern
Derek Lee Boire
 
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
将之 小野
 
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Derek Lee Boire
 
Measurements and Units
Measurements and UnitsMeasurements and Units
Measurements and Units
Ken Tominaga
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
SlideShare
 

Viewers also liked (8)

Writing Clean Code in Swift
Writing Clean Code in SwiftWriting Clean Code in Swift
Writing Clean Code in Swift
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
 
Standing the Test of Time: The Date Provider Pattern
Standing the Test of Time: The Date Provider PatternStanding the Test of Time: The Date Provider Pattern
Standing the Test of Time: The Date Provider Pattern
 
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
 
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
 
Measurements and Units
Measurements and UnitsMeasurements and Units
Measurements and Units
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to Common Challenges & Best Practices for TDD on iOS

Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
Gianluca Padovani
 
Successful Teams are TDD Teams
Successful Teams are TDD TeamsSuccessful Teams are TDD Teams
Successful Teams are TDD TeamsRob Myers
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
meghantaylor
 
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkUnit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
Long Weekend LLC
 
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Applitools
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
Gianluca Padovani
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
Gianluca Padovani
 
7 stages of unit testing
7 stages of unit testing7 stages of unit testing
7 stages of unit testing
Jorge Ortiz
 
Come si applica l'OCP
Come si applica l'OCPCome si applica l'OCP
Come si applica l'OCP
Andrea Francia
 
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
Daniel Bryant
 
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
JAXLondon2014
 
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
Srijan Technologies
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Shekhar Gulati
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
David Rodenas
 
Refactor your way forward
Refactor your way forwardRefactor your way forward
Refactor your way forward
Jorge Ortiz
 
Thucydides - a brief review
Thucydides - a brief reviewThucydides - a brief review
Thucydides - a brief review
Cristian COȚOI
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principlesEdorian
 
SwissJUG_Bringing the cloud back down to earth.pptx
SwissJUG_Bringing the cloud back down to earth.pptxSwissJUG_Bringing the cloud back down to earth.pptx
SwissJUG_Bringing the cloud back down to earth.pptx
Grace Jansen
 
Deploy your app with one Slack command
Deploy your app with one Slack commandDeploy your app with one Slack command
Deploy your app with one Slack command
Fabio Milano
 

Similar to Common Challenges & Best Practices for TDD on iOS (20)

Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Successful Teams are TDD Teams
Successful Teams are TDD TeamsSuccessful Teams are TDD Teams
Successful Teams are TDD Teams
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkUnit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava Talk
 
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
7 stages of unit testing
7 stages of unit testing7 stages of unit testing
7 stages of unit testing
 
Come si applica l'OCP
Come si applica l'OCPCome si applica l'OCP
Come si applica l'OCP
 
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
JAX London 2014 "Moving to DevOps Mode: easy, hard or just plain terrifying?"
 
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
Moving to a DevOps mode - easy, hard or just plain terrifying? - Daniel Bryan...
 
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
Refactor your way forward
Refactor your way forwardRefactor your way forward
Refactor your way forward
 
Thucydides - a brief review
Thucydides - a brief reviewThucydides - a brief review
Thucydides - a brief review
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
SwissJUG_Bringing the cloud back down to earth.pptx
SwissJUG_Bringing the cloud back down to earth.pptxSwissJUG_Bringing the cloud back down to earth.pptx
SwissJUG_Bringing the cloud back down to earth.pptx
 
Deploy your app with one Slack command
Deploy your app with one Slack commandDeploy your app with one Slack command
Deploy your app with one Slack command
 
I os tdd-with-bdd
I os tdd-with-bddI os tdd-with-bdd
I os tdd-with-bdd
 

Recently uploaded

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 

Recently uploaded (20)

A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 

Common Challenges & Best Practices for TDD on iOS

  • 1. TEST DRIVEN DEVELOPMENT COMMON CHALLENGES & 
 BEST PRACTICES FOR Tokyo iOS Meetup June 2016Derek Lee @derekleerock ON IOS
  • 2. COMMON PITFALLS & BEST PRACTICES FOR TDD YOUR PRESENTER Tokyo iOS Meetup June 2016Derek Lee @derekleerock 4/2015~11/2015 12/2015~ 1/2014~
  • 3.
  • 4. WHY TDD? Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 5. T D D Tokyo iOS Meetup June 2016Derek Lee @derekleerock Question What is TDD?
  • 6. TEST DRIVEN DEVELOPMENTTokyo iOS Meetup June 2016Derek Lee @derekleerock Question What is TDD?
  • 7. Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 8. WRITE A TEST MAKE IT PASS YADDA YADDA YADDA Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge Getting over the hump
  • 9. TDD CRASH COURSE Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge Getting over the hump
  • 10. TESTING WORKFLOW: RED → GREEN → REFACTOR ▸ Write a failing test ▸ Write the simplest implementation to make it pass ▸ Refactor ▸ Repeat Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 11. ▸ Compiler Errors = Failing Test Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP TESTING WORKFLOW: RED → GREEN → REFACTOR
  • 12. ▸ Red = Failing Test Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP TESTING WORKFLOW: RED → GREEN → REFACTOR
  • 13. ▸ Green = Passing Test Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP TESTING WORKFLOW: RED → GREEN → REFACTOR
  • 14. TESTING WORKFLOW: RED → GREEN → REFACTOR ▸ Keyboard Shortcuts for improving your test workflow: ▸ ⌘ + 5 → Show the Xcode Test Navigator ▸ ⇧ + ⌘ + U → Compile Tests ▸ ⌘ + U → Run All Tests In Suite ▸ MAGIC + U → Run all tests for current class ▸ MAGIC + G → Re-run last test * MAGIC = ⌃ + ⌥ + ⌘ Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 15. WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT ▸ Setup - Create objects needed to execute the test ▸ Action - Prod the subject (object) under test ▸ Verify - Make assertions about your expectations Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 16. WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT ▸ Override setUp() and tearDown() methods as needed Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 17. WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT ▸ Clearly indicate where the “Act” portion of your test is: Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 18. ▸ Use the appropriate assertion for your test expectation (XCTest) Tokyo iOS Meetup June 2016Derek Lee @derekleerock let number = 11 XCTAssertTrue(number == 12) error: -[MyProjectTests.MyObjectTest testMethod] : XCTAssertTrue failed - GETTING OVER THE HUMP WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
  • 19. ▸ Use the appropriate assertion for your test expectation (XCTest) Tokyo iOS Meetup June 2016Derek Lee @derekleerock let number = 11 XCTAssertEqual(number, 12) error: -[MyProjectTests.MyObjectTest testMethod] : XCTAssertEqual failed: ("Optional(11)") is not equal to ("Optional(12)") - GETTING OVER THE HUMP WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
  • 20. ▸ XCT Assertion Types ▸ AssertTrue, AssertFalse ▸ AssertEqual, AssertNotEqual (+WithAccuracy) ▸ AssertLessThan, AssertGreaterThan (+OrEqual) ▸ AssertNil, AssertNotNil ▸ AssertThrowsError Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
  • 21. ▸ Nimble (Matcher Framework) ▸ expect(~).to(~) or expect(~).toNot(~) ▸ expect(~).to(beTrue()) or expect(~).to(beFalse()) ▸ expect(~).to(beLessThan(~)) // greaterThan… ▸ expect(~).to(beAKindOf(~)) ▸ Can also write custom matchers with Nimble Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP WRITING TESTS TDD STYLE: ARRANGE → ACT → ASSERT
  • 22. GOLDEN RULES OF TDD ▸ Test First ▸ Simplest Solution ▸ Test Once ▸ Test in Isolation ▸ Test the interface, not the implementation Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 23. TDD BEST PRACTICES ▸ One Failing Test at a Time ▸ Create a Test List ▸ Assert First ▸ Simplest Test Data / Evident Test Data ▸ Avoid conditionals and loops Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 24. CLASSIC ▸ “Detroit” or “Chicago” ▸ Prefers real objects ▸ Focus: Algorithms ▸ State verification ▸ Test doubles as needed Tokyo iOS Meetup June 2016Derek Lee @derekleerock MOCKIST ▸ “London” ▸ Prefers mocks ▸ Focus: Object Interactions ▸ Behavior verification ▸ Test doubles always GETTING OVER THE HUMP
  • 25. CONTINUOUS INTEGRATION ▸ Build and test in a clean environment ▸ Automation of your test suite ▸ Test across OSs, simulators, devices ▸ Xcode Server, TeamCity, Travis, CircleCI, Jenkins… Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 26. CONTINUOUS INTEGRATION - XCODE SERVER BIG SCREEN Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 27. CONTINUOUS INTEGRATION - PIVOTAL PROJECT MONITOR Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 28. TAKING THE BLUE PILL ▸ BDD ▸ Clean Architecture ▸ SOLID Principles: SRP, Open/Closed, LSP, ISP, DIP ▸ Don’t Repeat Yourself ▸ Just In Time Design ▸ Refactoring ▸ Continuous Integration Tokyo iOS Meetup June 2016Derek Lee @derekleerock GETTING OVER THE HUMP
  • 29. MY TESTS TAKE FOREVER TO RUN Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge The Time-Consuming Test Run
  • 30. THE TIME-CONSUMING TEST RUN THE USUAL SUSPECTS ▸ Imbalanced Test Suite ▸ Testing Against External Resources Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 31. TESTING ICE-CREAM CONE ANTI-PATTERN Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 32. TESTING ICE-CREAM CONE ANTI-PATTERN Tokyo iOS Meetup June 2016Derek Lee @derekleerock ▸ Brittle ▸ Expensive to write/maintain ▸ Time consuming to run UI & MANUAL TESTS CAN BE…
  • 33. TESTING PYRAMID Tokyo iOS Meetup June 2016Derek Lee @derekleerock ] ] ARE WE BUILDING THE RIGHT SYSTEM? ARE WE BUILDING THE SYSTEM RIGHT?
  • 34. TESTING PYRAMID Tokyo iOS Meetup June 2016Derek Lee @derekleerock TIMETOTESTINCREASES
  • 35. THE TIME-CONSUMING TEST RUN DESIRED TEST SUITE QUALITIES FOR QUICK TEST FEEDBACK ▸ Few ▸ Fast ▸ Stable ▸ Thorough Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 36. THE TIME-CONSUMING TEST RUN WHEN TO RUN TESTS ▸ Current Unit/Feature → While building an object / feature ▸ All Units + All Feature → Before commit / push; after pulling updates from a repo; ▸ Integration, UI → CI Suite ▸ Manual → As needed Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 37. THE TIME-CONSUMING TEST RUN WHEN TO RUN TESTS ▸ Create a target for each suite of tests that you want to run Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 38. THE TIME-CONSUMING TEST RUN WHEN TO RUN TESTS ▸ Configure scheme(s) to execute tests: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 39. THE TIME-CONSUMING TEST RUN WHEN TO RUN TESTS ▸ Use a makefile with xcodebuild (or xctool) to execute the tests when you need to or from CI: Tokyo iOS Meetup June 2016Derek Lee @derekleerock units: @xcodebuild -project Osusume.xcodeproj -scheme "Osusume" -sdk iphonesimulator -destination "platform=iOS Simulator,OS=9.3,name= iPhone 6" build test integration: @xcodebuild -project Osusume.xcodeproj -scheme "Osusume-Staging" -sdk iphonesimulator -destination "platform=iOS Simulator,OS=9.3, name=iPhone 6" build test
  • 40. THE TIME-CONSUMING TEST RUN GUIDANCE ON UNIT TESTING - HOW/WHAT TO TEST ▸ Sandi Metz Rails Conf 2013 “The Magic Tricks of Testing” Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 41. THE TIME-CONSUMING TEST RUN DO MY TESTS HIT EXTERNAL DEPENDENCIES? ▸ Network, REST APIs ▸ Database (includes Core Data!) ▸ File System ▸ External Library or API Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 42. THE TIME-CONSUMING TEST RUN THEN HOW TO TEST EXTERNAL DEPENDENCIES? ▸ Find the seams where communication occurs ▸ Confirm expected interactions using mock objects ▸ Create an integration test if needed Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 43. THE TIME-CONSUMING TEST RUN GUIDANCE ON MOCK OBJECTS ▸ Martin Fowler, “Mocks Aren’t Stubs” http://martinfowler.com/articles/mocksArentStubs.html ▸ Uncle Bob, “The Little Mocker” Blog Post https://blog.8thlight.com/uncle-bob/2014/05/14/ TheLittleMocker.html Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 44. MY TEST SUITE FEELS UNSTABLE Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge The Brittle Test Suite
  • 45. THE BRITTLE TEST SUITE THE USUAL SUSPECTS ▸ Highly-coupled objects ▸ Long, complicated, or unreadable tests Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 46. THE BRITTLE TEST SUITE HIGHLY COUPLED OBJECTS - DESIGN & ARCHITECTURE ▸ TDD encourages us to write loosely coupled components that can be easily tested in isolation and combined later. ▸ May need to revisit your architecture ▸ “Build & Swap” ▸ Too difficult or too costly to refactor? ▸ TDD a new component and swap it in Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 47. THE BRITTLE TEST SUITE BUILD & SWAP EXAMPLE #1 - DRUM APP NAVIGATION UX Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 48. THE BRITTLE TEST SUITE BUILD & SWAP EXAMPLE #2 - MIKADO REFACTOR Tokyo iOS Meetup June 2016Derek Lee @derekleerock ▸ Parse Integration Before: ▸ One single “God” object singleton: ParseHelper.h/.m ▸ Included in 25 other classes ▸ Parse Integration After: ▸ 4 Dependency-Injected Testable “Repository” objects ▸ Can move each repository over as needed
  • 49. THE BRITTLE TEST SUITE HOW TDD HELPS ▸ Design ▸ Loosely coupled objects ▸ Well thought out public object APIs ▸ Dev ▸ Gives immediate feedback on quality ▸ Refactoring confidence Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 50. THE BRITTLE TEST SUITE HOW TO APPROACH ▸ Practice, practice, practice ▸ Reference Materials ▸ Read “Refactoring: Improving the Design of Existing Code” (Martin Fowler) ▸ Read “Working Effectively With Legacy Code” (Michael Feathers) Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 51. I DON’T KNOW HOW TO TEST X Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge Fear of the Unknown
  • 52. FEAR OF THE UNKNOWN THE USUAL SUSPECTS ▸ What to test - what not to test ▸ How to test specific objects, dependencies, scenarios Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 53. FEAR OF THE UNKNOWN KNOWING WHAT NOT TO TEST ▸ Private Methods (this is an implementation detail!) ▸ UI Design (fonts, colors, positions, constraints) ▸ Configuration Details (supporting data) ▸ Auto-generated code ▸ Test Fixtures, Test Doubles ▸ Reference: https://blog.8thlight.com/uncle-bob/ 2014/04/30/When-tdd-does-not-work.html Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 54. FEAR OF THE UNKNOWN HOW TO TEST… VIEW CONTROLLERS ▸ Move logic out of MegaController (*Andy Matuschak - https://realm.io/news/andy-matuschak-refactor-mega- controller/) ▸ Using Storyboards: ▸ Property Dependency Injection ▸ Without Storyboards: ▸ Constructor Dependency Injection Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 55. FEAR OF THE UNKNOWN HOW TO TEST… CORE DATA ▸ Use an in-memory Core Data Store ▸ Only setup data needed for test Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 56. FEAR OF THE UNKNOWN HOW TO TEST… UITABLEVIEW / UICOLLECTIONVIEW ▸ Extract Datasource and/or Delegate to external object for easier testing ▸ Leverage blocks / closures for common logic Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 57. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Swift: Mocks in Swift via Protocols (Blog post, Eli Perkins) http://blog.eliperkins.me/mocks-in-swift-via-protocols Tokyo iOS Meetup June 2016Derek Lee @derekleerock For Objective-C, see OCMock
  • 58. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Find the method definition(s) on the object that you need to confirm interactions with: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 59. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Create your own protocol definition to duplicate the method you want to confirm interaction with: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 60. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Create a fake object (spy) that implements that protocol: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 61. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Write your test: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 62. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Write the implementation: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 63. FEAR OF THE UNKNOWN HOW TO TEST… NSUSERDEFAULTS ▸ Pass in the real object for production code: Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 64. EASY TO FALL BACK TO OLD HABITS Tokyo iOS Meetup June 2016Derek Lee @derekleerock Challenge Commitment
  • 65. COMMITMENT THE USUAL SUSPECTS ▸ Frustration, Fatigue ▸ Cutting corners ▸ Falling back to what is most comfortable ▸ Test last or not testing at all Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 66. TOOLS YOU’LL NEED ▸ Focus ▸ Patience ▸ Tenacity ▸ Discipline ▸ Dedication Tokyo iOS Meetup June 2016Derek Lee @derekleerock COMMITMENT
  • 67. TIME MANAGEMENT HOW TO APPROACH ▸ Start Small ▸ 1% each day ▸ Think long-term: Investing in the future of your software Tokyo iOS Meetup June 2016Derek Lee @derekleerock
  • 68. REWARDS OF STICKING TO IT ▸ Making forward progress in small increments ▸ Allows refactoring to take place with confidence ▸ Identify bugs early and avoid regressions ▸ Reduces costs up-front ▸ Add new features knowing you won’t break existing ones ▸ Deploy anytime with confidence ▸ Easier to understand code for you and your team Tokyo iOS Meetup June 2016Derek Lee @derekleerock COMMITMENT
  • 69.
  • 70. @DEREKLEEROCK Thank you! Tokyo iOS Meetup June 2016Derek Lee @derekleerock