Goal is to demonstrate how to create an easy failing test as the first step in creating a test. This is the RED in Red, green, refactor. The student will write the test, learn how to execute the unit test and review the output in the Visual Dtudio test explorer. Student will perform this test for the Annual Salary function and 'Arrange' the variables, 'Act' by invoking the method needed to test and 'Assert' to confirm the test fails as expected.
- View Offline
- [Voiceover] We're going to create our first test case,…but a few things to note,…in test-driven development,…unit tests are set up using a three-step pattern…referred to as Arrange, Act, and Assert.…That is we arrange by initializing the objects…and setting the values that are needed,…and then we act by invoking the methods…on those objects.…Lastly, we check to see that the values…that we got back are what we we're expecting.…That is we assert by verifying that the action…of these methods behaved as expected.…
Now in our scenario,…there's going to be two methods,…one to determine the annual salary…and another to determine the hourly wage.…So let's start with the annual salary…by creating a test case,…and we'll go ahead and do that by renaming this to…AnnualSalaryTest.…Next, we'll go ahead and start the arrange process…by assuming that we have a SalaryCalculator.…
It tells us it's acting a little bit too smart…for its own good assuming that we want the project,…but that's not the case.…SalaryCalculator, let's say, sc…
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