S01E08: [TDD 🍅 7] Testing Table Views in Swift
In this episode, we finish the QuestionViewController
implementation by test-driving the table view delegate behavior.
We start by refactoring the delegate selection in the QuestionViewController
tests, and we lay out the UI to match the prototype. We then setup and run the application in the simulator to verify everything works as planned. However, we run into a bug!
To fix the bug, we use the same TDD discipline we've been practicing. We first write a test that replicates the unwanted behavior, and then we write the production code needed to make the test pass, which proves we've fixed the bug. By doing so, we added a missing test case that will prevent us from having regressions in the future and improved the overall quality of the project.
It's important to know that there are no silver bullets. This episode shows a case where TDD was not enough to protect us from a bug. When dealing with frameworks that you don't own, like UIKit
, you might find unexpected behaviors that will only get caught by running the application manually. However, when a bug is found, it's important to follow TDD to fix it and guarantee it won't recur.
As software developers, we should strive to create and follow processes and disciplines that improve the quality and reduce the cost of maintaining applications and at the same time increase our value as professionals.
Subscribe today to our Youtube channel and catch free new episodes every week and follow along the project's progress on GitHub.