Reporters are set using the [UseReporter(typeof(YourReporter))]
attribute. This can occur in 3 different places, and will be used in order of least surprise.
- On the method
- On the Class
- On the assembly
ApprovalTests suggest you make a assembly level configuration file for approvaltests named ApprovalTestsConfig.cs
:
[assembly: UseReporter(typeof(DiffReporter))]
If you wanted to have multiple reporters launch on failure, you can also combine as many as you wish using the following syntax:
[UseReporter(typeof(DiffReporter), typeof(FileLauncherReporter))]
Reporters help you in different ways
- To see differences in your test results
- To see how a test result would render
- To explore a test result or domain
- To approve / manipulate a test result
Based on what you are doing, you will want to switch which reporter you are using. Maybe even use multiple reporters at a time to accomplish different roles.
The main use for seeing differences is to use a reporter that will open a DiffTool. Full list of supported diff tools here
Let's say your test result is some HTML. In the beginning you might want to render it in a bowser to be able to see that it is indeed what you want. In this moment, try the FileLauncherReporter
. Which will open the .received.
file in the application associated to it on your machine.
This is useful for many types of test results including, xml, svg, csv, html, images, sound files, etc...
Like rendering, you might need to use different tools to examine a file to see that it's what you actually want. Sometimes you need to open them in excel or other places just to play. If you don't have a reporter that will open in your desired tool (and you don't want to build a custom one) you might just want to use the QuiteReporter
which will do nothing, allowing you to open whatever you need without disruption.
DiffTools can be a great way to approve most text files (just copy everything to the .approved.
file.) However, some DiffTools will break this because they are trying to help (prettifing, trimming or otherwise formatting the text)
The ClipboardReporter
or AllFailingTestsClipboardReporter
can be useful in these cases. Writing the command line text to move the files to your clipboard so you can paste them into your terminal to approve the test.