https://github.com/verifytests/verify.diffplex
Extends Verify to allow comparison of text via DiffPlex.
https://github.com/verifytests/verify.diffplex
Last synced: 12 months ago
JSON representation
Extends Verify to allow comparison of text via DiffPlex.
- Host: GitHub
- URL: https://github.com/verifytests/verify.diffplex
- Owner: VerifyTests
- License: mit
- Created: 2021-01-27T09:51:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-11T00:09:40.000Z (about 1 year ago)
- Last Synced: 2025-06-11T01:23:50.950Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 490 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
#
Verify.DiffPlex
[](https://github.com/orgs/VerifyTests/discussions)
[](https://ci.appveyor.com/project/SimonCropp/Verify-DiffPlex)
[](https://www.nuget.org/packages/Verify.DiffPlex/)
Extends [Verify](https://github.com/VerifyTests/Verify) to allow [comparison](https://github.com/VerifyTests/Verify/blob/master/docs/comparer.md) of text via [DiffPlex](https://github.com/mmanela/diffplex).
**See [Milestones](../../milestones?state=closed) for release notes.**
## Sponsors
### Entity Framework Extensions
[Entity Framework Extensions](https://entityframework-extensions.net/) is a major sponsor and is proud to contribute to the development this project.
[](https://entityframework-extensions.net)
## NuGet
* https://nuget.org/packages/Verify.DiffPlex
## Usage
### Initialize
Call `VerifyDiffPlex.Initialize()` in a `[ModuleInitializer]`. Alternatively, use `VerifyDiffPlex.Initialize(OutputType.Full)`, `VerifyDiffPlex.Initialize(OutputType.Compact)` or `VerifyDiffPlex.Initialize(OutputType.Minimal)` to specify the type of output (see below).
```cs
public static class ModuleInitializer
{
[ModuleInitializer]
public static void Initialize() =>
VerifyDiffPlex.Initialize();
[ModuleInitializer]
public static void OtherInitialize()
{
VerifierSettings.InitializePlugins();
VerifierSettings.ScrubLinesContaining("DiffEngineTray");
VerifierSettings.IgnoreStackTrace();
}
}
```
snippet source | anchor
### Verify text
Given an existing verified file:
```
The
before
text
```
And a test:
```cs
[Test]
public async Task Sample()
{
var target = @"The
after
text";
await Verifier.Verify(target);
}
```
### Diff results
When the comparison fails, the resulting differences will be included in the test result displayed to the user. This example shows the `Full` style of output.
```txt
Results do not match.
Differences:
Received: Tests.Sample.received.txt
Verified: Tests.Sample.verified.txt
Compare Result:
The
- before
+ after
text
```
### Output types
The library currently supports three different types of diff outputs; the desired type can be specified during library initialization.
```cs
[ModuleInitializer]
public static void Init() =>
VerifyDiffPlex.Initialize(OutputType.Compact);
```
snippet source | anchor
`OutputType.Full` is the default. It shows the full contents of the received file, with differences with the received file indicated by `+` and `-`. Here's an example of `Full` output.
```
First line
- Second line
+ Second line changed
Third line
Fourth line
Fifth line
- Sixth line
+ Sixth line changed
Seventh line
Eighth line
```
This output type gives the most information, but if verified files are long, it can be difficult to read through and find the actual differences. `OutputType.Compact` will show only the changed lines, with one line of context (with line number) before and after each changed section to help identify where the change is.
```
1 First line
- Second line
+ Second line changed
3 Third line
5 Fifth line
- Sixth line
+ Sixth line changed
7 Seventh line
```
Lastly, there is `OutputType.Minimal` which will show only the changed lines.
```
- Second line
+ Second line changed
- Sixth line
+ Sixth line changed
```
### Test level settings
DiffPlex can be used at the test level:
```cs
[Test]
public Task TestLevelUsage()
{
var target = "The text";
var settings = new VerifySettings();
settings.UseDiffPlex();
return Verify(target, settings);
}
```
snippet source | anchor
Or Fluently
```cs
[Test]
public Task TestLevelUsageFluent()
{
var target = "The text";
return Verify(target)
.UseDiffPlex();
}
```
snippet source | anchor