Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
iOS Unit Testing by Example
About the Pragmatic Bookshelf
Table of Contents
Early praise for iOS Unit Testing by Example
Foreword
Preface
How This Book Is Organized
Disclaimer: No SwiftUI Support
Online Resources
Acknowledgments
Pa rt 1 Foundations
Chapter 1: Assert Yourself
What Are Unit Tests Anyway?
Create a Place to Play with Tests
Write Your First Assertion
Add a Descriptive Message
Avoid Conditionals in Tests
Describe Objects upon Failure
Test for Equality
Test Equality with Optionals
Fudge Equality with Doubles and Floats
Avoid Redundant Messages
Choose the Right Assertion
Key Takeaways
Activities
What’s Next?
Chapter 2: Manage Your Test Life Cycles
Make a New Place to Play
Start from Test Zero
Hook Up Tests to Production Code
Examine Console Output
Observe Object Life Cycles to Learn the P hases of a Test
The Wrong Way to Reduce Duplicate Test Cod e
Learn How XCTest Manages Test Cases
Use setUp() and tearDown()
Key Takeaways
Activities
What’s Next?
Chapter 3: Measure Code Coverage and Add Tests
Make a New Place to Play
Enable Code Coverage
Examine Code Coverage Results
Drill into a Partially Covered Lin e
Add Tests for Existing Code
Cover a Conditional
Cover a Loop
Cover Statements in a Sequence
Avoid Percentage Targets, Embrace Forw ard Movement
Key Takeaways
Activities
What’s Next?
Chapter 4: Take Control of Application Launch
Make a New Place to Play
Observe the Default Behavior
Learn About the Test Launch Sequence
Bypass the Normal App Delegate
Put Up with the Initial View Control ler
Tweak Your Testing App Dele gate
Key Takeaways
Activities
What’s Next?
Chapter 5: Load View Controllers
Make a New Place to Play
Set Up a Storyboard-Based View Cont roller for Experiments
Load a Storyboard-Based View Control ler
Set Up a XIB-Based View Controller for Exp eriments
Load a XIB-Based View Controller
Set Up a Code-Based View Controll er for Experiments
Load a Code-Based View Controller
Key Takeaways
Activities
What’s Next?
Chapter 6: Manage Difficult Dependencies
Be Okay with Problem-Free Dependenc ies
Identify Difficult Dependencies
Create Boundaries to Isolate Dependencie s
Make a New Place to Play
Add Backdoors to Singletons You O wn
Subclass and Override: A Legacy Co de Technique
Inject Instances Through Initializer s or Properties
Inject Closures to Make New Instances
Key Takeaways
Activities
What’s Next?
Part 2: iOS Testing Tips and Techniques
Chapter 7: Testing Outlet Connections
Make a New Place to Play
Test Outlet Connections
Check the Effectiveness of Failure Mes sages
Key Takeaways
Activities
What’s Next?
Chapter 8: Testing Button Taps (Using Actions)
Make a Place to Play with a Button
Test Button Taps
Make a Test Helper for Button Taps
Key Takeaways
Activities
What’s Next?
Chapter 9: Testing Alerts
Make a New Place to Play
Add the Helper Framework to the Pro ject
Test Alerts Using the Alert Verifier
Move the SUT into the Test Fixture
Add Tests for Alert Buttons
Key Takeaways
Activities
What’s Next?
Chapter 10: Testing Navigation Between Screens
Make a New Place to Play
Set Up Code-Based Navigation
Set Up Segue-Based Navigation
Test Code-Based Push Navigation
Test Code-Based Modal Presentation
Test Segue-Based Push Navigation
Test Segue-Based Modal Navigation
Key Takeaways
Activities
What’s Next?
Chapter 11: Testing UserDefaults (with Fakes)
Make a New Place to Play
Isolate UserDefaults with Depen dency Injection
Extract a Protocol to Support Test Doubles
Make a Fake Object
Test UserDefaults
Key Takeaways
Activities
What’s Next?
Chapter 12: Testing Network Requests (with Mocks)
Make a New Place to Play
Isolate URLSession with De pendency Injection
Extract a URLSession Prot ocol for Test Doubles
Make a Test Spy
Design the Test Case
Promote the Test Spy into a Mock Object
Improve Mock Object Reporting
Key Takeaways
Activities
What’s Next?
Chapter 13: Testing Network Responses (and Closures)
Make a New Place to Play
Parse the Response
Start with a Fresh Test Spy
Design the Test Case
Test Asynchronous Code
Keep Asynchronous Code in Its Closure
Test an Error Scenario
Key Takeaways
Activities
What’s Next?
Chapter 14: Testing Text Fields (and Delegate Methods)
Make a Place to Play
Test the Outlets
Test Attributes and Wrangle UIKit Descriptions
Test Delegate Methods
Test Input Focus
Key Takeaways
Activities
What’s Next?
Chapter 15: Testing Table Views
Make a Place to Play
Test Table Views
Key Takeaways
Activities
What’s Next?
Chapter 16: Testing View Appearance (with Snapshots)
Make a Place to Play
Add FBSnapshotTestCase to a Test T arget
Set the Location for Reference Im ages
Write a Snapshot Test
See the Difference in a Snapshot Failu re
Manage Your Snapshot Tests
Key Takeaways
Activities
What’s Next?
Part 3: Using Your New Power
Chapter 17: Unleash the Power of Refactoring
What Is Refactoring?
Lay Out the Views for Our Practic e App
Add the Code to Our Practice App
Replace the Difficult Dependency with a Mock Object
Write the First Tests of the Change Password View Controller
Test the Cancel Button
Test the Submit Button
Test the Text Field Delegat e Method
Refactor to Break Up a Long Function
Extract a Method with Parameters
Clean Up a Few More Places
Key Takeaways
What’s Next?
Chapter 18: Refactoring: Moving to MVVM
What Is MVVM?
Replace String Literals to Use a View Model
Overwrite Storyboard Labels
Respond to Changes in the View Model
Move Logic into the View Model
Key Takeaways
What’s Next?
Chapter 19: Refactoring: Moving to MVP
What Is MVP?
Set Up the MVP Types
Extract Methods into the View Comm ands Protocol
Move a Function into the Pr esenter
Remove the didSet Observer
Use Refactoring Principles to Reparent a Swift Type
Move Several Functions to the Pres enter
Extract Password Validation into Its O wn Type
Finish Up the Refactoring to MVP
Key Takeaways
What’s Next?
Chapter 20: Test-Driven Development Beckons to You
What Is TDD?
Make a New Place to Play with TDD
Define the Requirements of the Time -of-Day Greeter
Design the First Failing Test with Bar e Production Code
Make the First Test Pass with “Good M orning”
Refactor the First Test to Make I t More Expressive
Repeat the TDD Steps for the Second T est
Add Tests to Expand “Good Afternoo n”
Implement “Good Evening”
Step Back to Refactor the Method as a Whole
Add the Name to the Greeting
Key Takeaways
What’s Next?
Bibliography
You May Be Interested In…
← Prev
Back
Next →
← Prev
Back
Next →