Reporters are the part of Approval Tests that launch diff tools when things do not match. On this page we show you three different ways to configure which reporters are used.
Because there are a few different ways to configure a reporter in Approval Tests, if you are using multiple methods to configure a reporter (this is very common) you may wonder;
Which configuration will be used?
ApprovalTests uses the method of Principle of Least Surprise.
This means the reporter used is the one declared closest to the test.
Below are three different options in order, starting with the least surprising.
All the verify functions have an overload that takes an Options parameter. You can configure the reporter via the Options like such:
Options options = new Options().withReporter(ReportWithBeyondCompare.INSTANCE);
Approvals.verify(objectUnderTest, options);At both the class and method level you can use the @UseReporter attribute to set 1 or multiple reporters.
@UseReporter(ReportWithDiffMerge.class)@UseReporter({DiffReporter.class, ClipboardReporter.class})Note: If you use multiple reporters ALL of them will report. Not just the first one.
You can also assign a default for an entire package (and all sub-packages) by creating a PackageSettings class. Here is an example
public class PackageSettings
{
public static ReportWithTkDiffMac UseReporter = ReportWithTkDiffMac.INSTANCE;
public static CountingReporter FrontloadedReporter = new CountingReporter();
}You can find out more about Package Level settings here
Lastly, it is possible to set the APPROVAL_TESTS_USE_REPORTER environment variable to influence the reporters. Setting a reporter through the environment overrides all other reporters - so use this sparingly and only to change reporter behaviour for individual runs or on individual machines.
The environment variable can take any combination of the following values. Multiple values should be separated by a comma, without whitespace.
AraxisMergeReporter
AutoApproveReporter
AutoApproveWhenEmptyReporter
BeyondCompareReporter
ClipboardReporter
CodeCompareReporter
DelayedClipboardReporter
DiffMergeReporter
DiffReporter
FileCaptureReporter
ImageReporter
ImageWebReporter
IntelliJReporter
JunitReporter
KDiff3Reporter
KaleidoscopeDiffReporter
MeldMergeReporter
P4MergeReporter
PitReporter
QuietReporter
TestNgReporter
TextWebReporter
TkDiffReporter
TortoiseDiffReporter
VisualStudioCodeReporter
WinMergeReporter
WindowsDiffReporterFor example, setting APPROVAL_TESTS_USE_REPORTER=AutoApproveReporter allows you to approve all pending changes at once
without modifying the source code and rebuilding the code to temporarily choose a different reporter. Similarly, setting
APPROVAL_TESTS_USE_REPORTER=MeldMergeReporter allows you to explicitly choose a reporter you want to use locally,
without influencing the default reporter priorities and setup for fellow developers.
See Also: Reporters