public interface Reporter
Approvals-Java, as many other Approval Testing frameworks, relies on comparisons between data which has been approved by the developer, and data which is computed from the Program Under Tests.
In case there’s any difference found during the comparison, the framework needs to be able to report those differences to the developer. There are plenty of ways to report those differences, like generating assertions errors, logging the differences in a file, or whatever you can imagine.
The Reporter interface is the contract used by the framework to report the differences found during computing the comparisons.
There will be a set of reporters already implemented and provided by the framework, but people can implement their owns and use them while computing the approvals.
| Modifier and Type | Field and Description |
|---|---|
static Reporter |
DEFAULT
Global property allowing to retrieve the default reporter for the current execution context.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
isAvailable()
A
Reporter may not be relevant in all contexts, and they should provide some automated checks validating that they’re actually able to perform what they’re supposed to do in the current execution customFiles (like libraries available in the classpath or Diff / Merge programs available on the computer). |
void |
mismatch(ApprovalFiles files)
A
Reporter is called whenever a difference is found while comparing the output of a Program Under Tests and the existing approved files linked to the tests. |
static final Reporter DEFAULT
Global property allowing to retrieve the default reporter for the current execution context.
Careful, that default reporter is completely dependent on the execution context (OS, classpath, etc.).
If no native supported diff or merge tool is found (this happens in CI for instance), it falls back to throwing exceptions.
void mismatch(ApprovalFiles files)
A Reporter is called whenever a difference is found while comparing the output of a Program Under Tests and the existing approved files linked to the tests. That method is the one which will be called by the framework, specifying the approved and received files which present differences.
It is then used to implement the behavior to execute for dealing with that mismatch between both files.
files - the ApprovalFiles which holds the approved file (which contains the data reviewed and approved by the developer) and the temporary received file (which contains the data generated by the Program Under Tests)AssertionError - if the implementation relies on standard assertions provided by a framework like JUnitRuntimeException - if it relies on executing an external command which failedboolean isAvailable()
A Reporter may not be relevant in all contexts, and they should provide some automated checks validating that they’re actually able to perform what they’re supposed to do in the current execution customFiles (like libraries available in the classpath or Diff / Merge programs available on the computer).
This method allows to state if a Reporter should be executed in case any differences are found during the comparison of approved and received files. If it returns false, the Reporter won’t be used.
Reporter can be used in the current execution customFiles.Copyright © 2018–2019 Write Them First!. All rights reserved.