In Test Driven Development, there’s the process of Red-Green-Refactor. In the Green stage, it's all about passing tests. It's important that a unit test can correctly detect passing tests to prevent false negatives. After having set up a failing test, Reynald intentionally creates a passing test to confirm Visual Studio's testing suite detects it.
- [Instructor] After the red phase, where you create a test that fails in test-driven development, is the green phase where you update it so your tests pass. Now I relaunched the project and you can see that no tests were run as of yet. But if we run the test like we did in our last exercise, it failed. So now we're going to go ahead and update this so that it passes. So let's navigate to our salary calculator and since we are now in the green phase, let's remove this zero and semicolon and the comment and return what it is supposed to, which is the annual salary.
I'll save that and Build and now we can go ahead and run the test again which we could also do on the Test Explorer option, Run all. And we see that we have a passing test and that's exactly what we expect for the green phase. Now the last phase would be refactor. So we're not going to go ahead and do that but I would like to explain what that is. Simply refactoring is just a matter of rearranging and updating your code so that it is more legible, more concise and then after you clean it up, you re-run the test to make sure that it still passes.
So that's it, that's just a taste of test-driven development in this exercise but definitely check out my course C# Test Driven Development for more in-depth look into the process. It really is an art form and very important to know how to do in order to save you a lot of headache when you're programming big applications.
- Understanding CLR and FCL
- Working with the .NET compiler
- Setting up Visual Studio to code with ASP.NET Core
- Creating an ASP.NET MVC 6 app
- Creating a web API
- Working with C# features
- Testing in C#
- Deploying cross-platform .NET apps