How to Use A Custom Reporter

This guide is for creating the ability to use a custom reporter that works on your machine.

For figuring out how to make a more robust custom reporter, that you might want to submit back to us as a Pull Request, check out How to Submit a New Reporter to ApprovalTests.

Let’s say that you really enjoy using Sublime Merge, and on your system it’s located in "/Applications/Sublime"

If you were to run this the command line, the full command would look this this:

"/Applications/Sublime" mergetool --no-wait "test.received.txt" "test.approved.txt" -o "test.approved.txt" &

(See snippet source)

You can do this simply by creating a Reporter using:

auto path = "/Applications/Sublime";
auto arguments = "mergetool --no-wait {Received} {Approved} -o {Approved}";
auto reporter = ApprovalTests::CustomReporter::create(path, arguments);

(See snippet source)

By default, this will run in the background. Most of the time this is what you want.

However, you can force it to run in the foreground with:

auto reporter =
    ApprovalTests::CustomReporter::createForegroundReporter(path, arguments);

(See snippet source)

On Windows, you can specify a search path for the installed location of a program with {ProgramFiles}.

auto path = "{ProgramFiles}Beyond Compare 4\\BCompare.exe";
auto reporter = ApprovalTests::CustomReporter::create(path);

(See snippet source)

See Registering a default reporter for wiring up this reporter as default, or you can dereference it and pass it in to individual verify("text", *reporter) method calls…