Write a test that passes with the existing code, then change it so that it fails for the new desired behavior.
- [Instructor] Before we start TDD-ing our new changes,…it's a good idea to add test coverage…to the areas you'll be modifying.…Not only does this improve your test coverage,…but when you make your changes, it gives you confidence…that you haven't broken any existing behavior.…We're going to be making changes in the booking controller…and the booking service classes.…Let's start with a test for the booking service.…We have a blank test file here where…I'm going to be adding my test for the booking service class.…I already wrote the test needed for this method.…You can find them in the course files for this video.…
I'm going to copy this in and paste.…Now, we can run the test.…Cool, so now we can start TDD on this class.…Let's start by copying this test,…and we'll rename it to DiscountsCouponCode.…Next, we know that our method is going to need…to pull data from the coupon repository,…so let's add a mock for that.…We'll scroll up,…and add a new private mock to our tests…for the ICouponRepository,…collect CouponRepo, and we'll add in the constructor, too.…
Note: Examples in this course were developed using C# ASP.NET Core, but the concepts apply to all .NET Core applications.
- Getting the TDD tools
- Testing cases
- Refactoring code
- Completing test cases
- Testing changes in untested code
- Changing code