Join Reynald Adolphe for an in-depth discussion in this video Create another test, part of C# Test Driven Development.
- [Voiceover] Okay, so we've completed…our annual salary unit test.…Now, it's time to create our second test…which is called "HourlyWageTest"…and that's gonna calculate the hourly wage…based on an annual salary.…So, to save some time,…why don't we go ahead and just copy…our first test, duplicate that,…and make the necessary updates.…So we know it's gonna be called…"HourlyWageTest"…and instead of annual salary,…we're going to be getting an hourly wage as a decimal…and we get that by calling on a method…called "GetHourlyWage,"…and we are going to be passing in…an annual salary of 52,000.…
For the assertion, let's say we're assuming that…it's going to be $25 an hour,…and we are comparing that to the hourly wage.…So we can save and build, and of course,…it doesn't compile.…That's expected because we haven't created…hourlyWage yet, which you'll go ahead and do now.…Let's go ahead and add just enough logic…in the salary calculator so that it compiles.…
We'll create a public method that returns a decimal…called "GetHourlyWage" that takes in an integer…
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