© Gio Lodi 2021
G. LodiTest-Driven Development in Swifthttps://doi.org/10.1007/978-1-4842-7002-8_14

14. Fixing Bugs and Changing Existing Code with TDD

Gio Lodi1  
(1)
Mount Martha, VIC, Australia
 

How do you apply Test-Driven Development to change the behavior of existing code or fix a bug?

The same way as you do to write new code: by using the tests’ feedback to identify the changes to make.

When updating existing behavior, you can start by editing its tests. If you have a bug to fix instead, you first write a failing test that reproduces it and then make the test pass to fix it.

Fixing Bugs Driven by Tests

The early feedback from the beta testers reported a bug in the app. After submitting an order, customers still see the checkout button, making them ...

Get Test-Driven Development in Swift: Compile Better Code with XCTest and TDD now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.