Goal is to have student know what mocking is and be familiar with different kinds of mocking tools for Test Driven Development. These include FakeItEasy, Nsubstitute and Moq. References to their websites are also provided. Mocking patterns are also discussed such as Fakes (classes that implement an interface but take shortcuts), Stubs (which provide predefine values to method calls ) and Mocks (which allows you to validate if a method was called or not).
- [Voiceover] The tools we just discussed…are used to create unit test.…Now, sometime called that's being tested…might need data like customer records,…or products.…And if fits new project…that data might not even exist.…But even if it did…when it comes to testing…we don't wanna use real data from production,…because, that could cause problems we don't want,…like accidents in over ridding it.…Our primary concern during test driven development…is to ensure all code we write…is functioning correctly through unit test,…and any input data that's needed…should be simulated or mocked up.…
We do this by using Mocking Frameworks.…FakeItEasy is a popular framework…and in this library,…all objects are considered fakes,…but their usage,…determines whether they act as mock…or stubs.…And we'll talk about what those are next.…To learn more about…FakeItEasy you can go to their website…on fakeiteasy.github.io.…and review more documentation about it.…NSubstitute is another library,…but it claim to fame…is that the syntax use…is a vibic more succinct,…
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