Goal is to demonstrate how to create a simple passing test. The GREEN in Red, Green, Refactor. The student will write the core program needed to pass the unit test. In this case, the GetAnnualSalary method will be generated will all code needed to pass the test. This method will be contained in a SalaryCalculator class. Once coded, student will validate test pass as expected.
- View Offline
- [Voiceover] We are now in the green phase…and ready to update our unit test to pass.…First thing I'd like to do though is I want to go ahead…and rename this to something more fitting.…Let's rename this to Calculator Test.…Now what we want to do is we know that we don't have…this salary calculator class existing yet.…So, let's go ahead and do that.…We can do this by creating a new project.…
Just right-clicking on the solution and going to Add,…we have an option, a context menu, to choose…New Project...…and if we click on Visual C#…we'll get an option to choose Class Library.…Here we can type in Calculator.…Click OK.…Looks good.…Now, what we want to do is inside Class1,…let's go ahead and ...…
name this SalaryCalculator.…And then what we want to do is add just enough code…for our project to compile.…Let's go ahead and type in the method…that we want which is called GetAnnualSalary.…We know that...…if we look back…we know that we are going to need this method.…Right now this SalaryCalculator class…is in the process of being created.…
In this course, Reynald Adolphe explains the principles of test-driven development and shows how to apply them to two different C# workflows. First, he creates a new test-driven project. He writes the test cases before the code to drive the design of the program. In the second scenario, he writes test cases for an existing C# project, to find bugs before it goes live. Along the way, Reynald uses Microsoft's MSTest, but he also introduces other testing tools (such as the unit testing framework xUnit and the mocking framework Moq) and theories (such as the red-green-refactor mantra and SOLID principles) that make test-driven development so efficient.
- Different approaches to testing
- Using testing tools and mocking frameworks
- Creating a simple C# test-driven project
- Adding a failing test
- Updating tests to pass
- Refactoring code
- Using Moq to test data