Goal is to demonstrate how to create a failing test as the first step in creating a test for a more complex project. Student will create four different failing test cases. Two will be to determine correct output string stating salary for an employee contractor respectivley. Two following test cases will be created to test the negative condition to confirm failed conditions are caught for emplyoyees & contractors.
- [Voiceover] Alrighty. So, before we get started,…just a note.…I made a couple of changes to the code…by returning the result of the string…so we can unit-test against it.…If you can see here, on line 15,…I entered return result…and set that variable on line 11.…Before, it was just writing for the console,…so if you want to follow along,…please go ahead and go to chapter four exercise two…and you can open the solution from there.…Because we're in a red phase,…we want to write some failing tests now.…
And the first thing we need to decide…is what method to test.…Now, we're going to test both of them…but let's say we are going to start with…calculate weekly salary for an employee.…The next thing we need to do…is to think of the parameters we need to use.…Now, in our case, let's go ahead and use the same ones…and pass in 55 for the hours and 70 for the wage.…What we want is to determine is that the output statement…with salary calculator is correct.…
But at this point, we want it to fail.…So, when we're arranging,…I'm going to go ahead and exclude the salary formula…
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