From the course: ASP.NET Core: Test-Driven Development

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

TDD in untested code

TDD in untested code

- [Instructor] It's all well and good TDDing new code, but often in the real world, you actually have to edit some existing code. Our client, Landon Hotel, wants us to make a change to some existing code. They have a feature to calculate a booking price and now they want to add the option for a coupon code. So, the big problem is, this code is untested and not written in a way that's currently unit testable. So this chapter is going to focus on how we can apply TDD practices on code that's currently in an untestable state. So here's what we'll be doing, first we'll be identifying where we need to make the change. Then, once we've done that, we can extract out their dependencies to make use of dependency injection. Then, we'll be writing tests to cover the existing behavior, just so when we're making any new changes, we don't break any of the existing stuff. And finally, we'll be applying TDD practices to make our new changes.

Contents