SlideShare a Scribd company logo
1 of 70
Download to read offline
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 2010guest5639fa9
 
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 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 DevelopmentShawn 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 iOSPablo 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 DevelopmentTung Nguyen Thanh
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentJohn Blum
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Test driven development
Test driven developmentTest driven development
Test driven developmentNascenia IT
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Developmentsatya 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 SkeletonSeb 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 SwiftDerek 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 ProductivityDerek 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 PatternDerek 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 UnitsKen 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 & TricksSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

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 Autofacmeghantaylor
 
Unit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkUnit Testing in iOS - Ninjava Talk
Unit Testing in iOS - Ninjava TalkLong 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 (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 testingJorge Ortiz
 
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
 
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
 
[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 AppiumSrijan 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: TDDDavid Rodenas
 
Refactor your way forward
Refactor your way forwardRefactor your way forward
Refactor your way forwardJorge Ortiz
 
Thucydides - a brief review
Thucydides - a brief reviewThucydides - a brief review
Thucydides - a brief reviewCristian 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.pptxGrace 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 commandFabio 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
 
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...
 
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?"
 
[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

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 

Recently uploaded (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

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