ENGLISH

Test-Driven Development in Swift: Compile Better Code with XCTest and TDD

Book information

Publisher
Apress
Year
2021
ISBN
1484270010, 9781484270011
Language
english
Format
PDF
Filesize
4 MB (3724918 bytes)
Edition
1
Pages
307\296
Time added
2021-07-01 15:31:36

Description

Leverage Swift to practice effective and efficient test-driven development (TDD) methodology. Software testing and TDD are evergreen programming concepts―yet Swift developers haven't widely adopted them. What's needed is a clear roadmap to learn and adopt TDD in the Swift world. Over the past years, Apple has invested in XCTest and Xcode's testing infrastructure, making testing a new top priority in their ecosystem. Open-source libraries such as Quick and Nimble have also reached maturity. The tools are there. This book will show you how to wield them.  TDD has much more to offer than catching bugs. With this book, you’ll learn a philosophy for building software. TDD enables engineers to solve problems incrementally, writing only as much code as necessary. By decomposing big problems into small steps, you can move along at a fast pace, always making visible progress.  Participate in the test-driven development journey by building a real iOS application and incorporating new concepts through each chapter. The book's concepts will emerge as you figure out ways to use tests to drive the solutions to the problems of each chapter. Through the TDD of a single application, you’ll be introduced to all the staples and advanced concepts of the craft, understand the trade offs each technique offers, and review an iterative process of software development.  Test-Driven Development in Swift provides the path for a highly efficient way to make amazing apps. What You'll Learn Write tests that are easy to maintain Look after an ever-growing test suite Build a testing vocabulary that can be applied outside the Swift world See how Swift programming enhances the TDD flow seen in dynamic languages  Discover how compiler errors can provide the same helpful guidance as failing tests do Who This Book Is For Mid-level developers keen to write higher quality code and improve their workflows. Also, developers that have already been writing tests but feel they are not getting the most out of them.  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

Similar books

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

2010 · PDF

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

1858 · PDF

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

2022 · PDF

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

1809 · PDF