Skip to content

Latest commit

 

History

History
91 lines (57 loc) · 3.81 KB

ReportersGettingStarted.md

File metadata and controls

91 lines (57 loc) · 3.81 KB

Getting Started with Reporters

Contents

Configuring Reporters

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.

  1. On the method
  2. On the Class
  3. On the assembly

ApprovalTests suggest you make a assembly level configuration file for approvaltests named ApprovalTestsConfig.cs:

[assembly: UseReporter(typeof(DiffReporter))]

snippet source | anchor

Launching Multiple Reporters

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))]

snippet source | anchor

When to use different reporters

Reporters help you in different ways

  1. To see differences in your test results
  2. To see how a test result would render
  3. To explore a test result or domain
  4. 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.

Differences

The main use for seeing differences is to use a reporter that will open a DiffTool. Full list of supported diff tools here

Rendering

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...

Exploring Results

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.

Approving

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.


Back to User Guide