ApprovalTests is an open source library that enables unit tests to go beyond simple asserts. It allows complex verification of system output that would otherwise be hard and time-consuming to implement using conventional asserting. It is also an essential tool to quickly get legacy code under test before refactoring it.
Introduction Hi I'm Jason Roberts from Pluralsight, welcome to this course on Approval Tests for. NET. In this module we're going to get an overview of approval tests. So we're going to start by comparing asserts from traditional testing frameworks with the approval tests approach. So here we'll just look at some of the conceptual high level differences. We'll look at where we might want to use approval tests, so we'll see that approval tests are helpful when we're dealing complex outputs, for example, and also when we're testing legacy code bases. Next we'll look at the concept of approved and received files when we're using approval tests. So we'll look at the difference between these two types of files and we'll also learn what gets checked into source control. Next we'll take a look at the installation, so we'll learn how we can install approval tests from NuGet and also the testing frameworks that approval test supports. Finally we'll look at a simple demo of using approval tests, so we'll see how to install the NuGet package in Visual Studio, how to create an initial test, and then we'll see the approved and received files in use.
Verifying Objects and Arrays Hi welcome back. In this module we're going to look at some ways we can verify more complex objects and also arrays of things. So we're going to start off by learning how we can verify custom objects. And to do this we're going to see an example of how we can use approval tests with a Hangman game engine. To create our verification, we're going to see how we can override the two string method in our game engine to provide a string that represents our game engine state. And then how we can use this string in our verifications. Next we're going to see how we can approve intermediate states in our tests so again we're going to use the Hangman game engine example. And we'll see how we can create an approval that represents multiple states that the engine has gone through. To do this we're going to refactor our original test code for the Hangman game verification and we're going to take more control of the verification string that we use. Next we'll look at how we can refactor a traditional array test. So typically if we've performed an operation on an array, we want to assert that each element in the array is correct. So we'll start with a traditional test, which uses multiple assertations and we'll see how we can refactor this to instead use an approved file. Finally we'll learn how to create an approval, which represents a function that gets called on each element of an input array. So in this way we can approve that the function works with varying input parameters. So we'll start with an array and we'll run a function against each item in this array. We'll see how the execution of the function against each item results in an overall approval file. And finally we'll see how we can add some additional context by using a different overload.
Reporters Hi welcome back. Up until this point we've kept the idea of reporters somewhat to the background. In this module we're going to dig in more deeply about the concept of reporters in approval tests. So first off we're going to start by getting a high level overview of reporters and we're going to see how they do things such as render results to us and also how they can increase our understanding of the result or allow us to increase the granularity of something that's not working. First reporter will take a look at is the file reporter. And this reporter allows us to launch an associated program depending on the type of file that we're received. Next we'll look at the clipboard reporter and the clipboard reporter allows us to paste an approval command into a command window to create an approved file from a received file. We'll see that in addition to text diff we can also do image diff comparisons. So we'll learn how we can see the differences between approved and received images. Instead of defining reporters using attributes in our tests, we'll also learn how we can define them in the config file for the test project. We'll learn about the different levels we can use the reporter attributes. And we'll dig into more detail on the diff reporter itself. So here we'll see the inheritance hierarchy for the diff reporter and we'll see the underlying mechanism for the reporters that allows reporters to be chained together and allows approval tests to select the first reporter that's able to run in a given environment. And finally we'll take this knowledge and we'll apply it to creating our own custom reporter that we can use with approval tests.