Test-driven development in Swift compile better code with XCTest and TDD
Otros Autores: | |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
New York, New York :
APress
[2021]
|
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009626961006719 |
Tabla de Contenidos:
- Intro
- Table of Contents
- About the Author
- About the Technical Reviewer
- Acknowledgments
- A Gift for You
- Chapter 1: Why Test-Driven Development?
- What Is a Test?
- Manual Testing Is Inefficient
- Code That Checks Other Code
- From Writing Tests to Writing Tests First
- From Writing Tests First to Test-Driven Development
- Key Takeaways
- Endnote
- Chapter 2: XCTest Introduction
- The Xcode Unit Test Target
- XCTestCase and Equality Assertion
- Other Assertions
- Unwrapping Optionals
- Expectations for Asynchronous Code
- XCTestCase Life Cycle
- Key Takeaways
- Chapter 3: Getting Started with Test-Driven Development
- Test List
- Fake It...Till You Make It
- Arrange, Act, Assert
- First Make the Test Pass
- then Make the Code Clean
- The Compiler Is Part of the TDD Process
- Wishful Coding
- Key Takeaways
- Chapter 4: Test-Driven Development in the Real World
- The Menu Ordering App
- Where to Begin?
- Partition Problem and Solve Sequentially
- Building the Menu
- Use the Strictest Assertions Possible
- Use the Clearest Assertion Possible
- Don't Let the Tests Crash
- Test Naming Conventions
- Red, Green, and Don't Forget Refactor
- Wiring Up the UI
- Pure Functions
- Key Takeaways
- Chapter 5: Changing Tests with Fixtures
- The Hidden Cost of Source Changes
- Fixtures
- Fixtures vs. Convenience Initializers
- Fixtures Make the Test Actors Explicit
- Fixtures Are Composable
- Introduce Fixtures As Early As Possible
- Practice Time
- Key Takeaways
- Endnote
- Chapter 6: Testing Static SwiftUI Views
- The Problem with Presentation Logic in the View
- Decouple Presentation Logic from the View Implementation
- Preparatory Refactor: Reduce the Working Surface Area
- ViewModel
- Using the ViewModel in the View
- Beyond Testability
- ViewModels Everywhere!
- Key Takeaways
- Endnotes.
- Chapter 7: Testing Dynamic SwiftUI Views
- How SwiftUI and Combine Make Seamless View Updates Possible
- Make the ViewModel Stream Updates with ObservableObject
- The Dependency Inversion Principle
- Decouple the ViewModel from the Data Fetching with DIP
- How to Test Async Updates of @Published Properties
- Mystery Guest
- Practice Time
- Key Takeaways
- Chapter 8: Testing Code Based on Indirect Inputs
- The Stub Test Double
- Make Error Handling Explicit with Result
- Practice Time
- Key Takeaways
- Chapter 9: Testing JSON Decoding
- Option 1: Inline Strings
- Option 2: JSON Files
- Which Option to Choose?
- Is Testing JSON Decoding Worth It?
- Practice Time
- Key Takeaways
- Endnote
- Chapter 10: Testing Network Code
- Why You Shouldn't Make Network Requests in Your Unit Tests
- How to Decouple the Unit Tests from the Network
- Simulate Network Requests Using a Stub
- A Third-Party Alternative
- Practice Time
- Key Takeaways
- Endnote
- Chapter 11: Injecting Dependencies with @EnvironmentObject
- How Dependency Injection Keeps Each Test Isolated
- Dependency Injection vs. Directly Accessing Shared Instances
- Dependency Injection with @EnvironmentObject
- The Downside of @EnvironmentObject
- @EnvironmentObject vs. Directly Accessing Shared Instances
- Practice Time
- Key Takeaways
- Chapter 12: Testing Side Effects
- Third-Party Dependencies Are the Same As All Dependencies
- The Benefit of Abstracting Third-Party Dependencies
- Build Wrappers for Third-Party Dependencies
- The Spy Test Double
- The Downside of Using Spies
- Practice Time
- Key Takeaways
- Chapter 13: Testing a Conditional View Presentation
- Informing the User of the Checkout Completion
- How to Test Asynchronous Code When There Is No Callback
- Wiring Up the View
- Testing the Alert Dismiss Behavior
- Key Takeaways.
- Chapter 14: Fixing Bugs and Changing Existing Code with TDD
- Fixing Bugs Driven by Tests
- Changing Existing Code Driven by Tests
- Key Takeaways
- Chapter 15: Keeping Tests Isolated with Fakes and Clear with Dummies
- Fake: How to Bypass Slow or Stateful Dependencies
- Dummy: How to Provide Dependencies That Are Required but Irrelevant for the Behavior Being Tested
- Key Takeaways
- Chapter 16: Conclusion
- More Than Just Testing
- TDD and Software Design
- TDD and Productivity
- TDD and Product Development
- Endnote
- Cheatsheet
- XCTest Test Structure
- How to Test Asynchronous Code
- How to Test Asynchronous Code When There Is No Callback
- How to Test Combine Publishers
- How to Test Changes to SwiftUI @Published Properties
- Fixture Extension
- Stub Test Double
- Spy Test Double
- Fake Test Double
- Dummy Test Double
- Appendix A: Where to Go from Here
- Continuous Integration
- Snapshot Testing
- UI Testing
- API Integration Testing
- Use Modularization to Tame Long Build Times
- How to Convince Your Team to Adopt TDD
- Appendix B: Testing with Quick and Nimble
- Nimble
- Quick
- Appendix C: TDD with UIKit
- How to Unit Test a UIViewController
- How to Test Table Views
- How to Test ViewController Navigation and Presentation
- What About AppKit and WatchKit?
- Index.