Meziantou.Framework.InlineSnapshotTesting
1.0.24
Prefix Reserved
See the version list below for details.
dotnet add package Meziantou.Framework.InlineSnapshotTesting --version 1.0.24
NuGet\Install-Package Meziantou.Framework.InlineSnapshotTesting -Version 1.0.24
<PackageReference Include="Meziantou.Framework.InlineSnapshotTesting" Version="1.0.24" />
paket add Meziantou.Framework.InlineSnapshotTesting --version 1.0.24
#r "nuget: Meziantou.Framework.InlineSnapshotTesting, 1.0.24"
// Install Meziantou.Framework.InlineSnapshotTesting as a Cake Addin #addin nuget:?package=Meziantou.Framework.InlineSnapshotTesting&version=1.0.24 // Install Meziantou.Framework.InlineSnapshotTesting as a Cake Tool #tool nuget:?package=Meziantou.Framework.InlineSnapshotTesting&version=1.0.24
Meziantou.Framework.InlineSnapshotTesting
Meziantou.Framework.InlineSnapshotTesting
is a snapshot tool that simplifies the assertion of complex data models and documents. It is inspired on Verify.
InlineSnapshot
is called on the test result during the assertion phase. It serializes that result and update the expected value. On the next test execution, the result is again serialized and compared to the existing value. The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be updated to the new result.
On the development machine, a diff tool prompt to compare the expected snapshot with the current snapshot. So, you can accept the new value or cancel. So, you can quickly iterate on your code and update snapshots.
How does it work
First you can write a test with the following code:
var data = new
{
FirstName = "Gérald",
LastName = "Barré",
NickName = "meziantou",
};
// No need to write the expected value
InlineSnapshot.Validate(data, "");
Then, run the tests. It will show you a diff tool where you can compare the expected value and the new value. Once you accept the change, the test is updated:
var data = new
{
FirstName = "Gérald",
LastName = "Barré",
NickName = "meziantou",
};
InlineSnapshot.Validate(data, """
FirstName: Gérald,
LastName: Barré,
NickName: meziantou
""");
Other features
Configuration
You can configure the default behavior of Validate()
by settings InlineSnapshotSettings.Default
. In the case of unit tests, you may want to update the configuration before running tests. You can use a ModuleInitializer
to do so.
static class AssemblyInitializer
{
[ModuleInitializer]
public static void Initialize()
{
InlineSnapshotSettings.Default = InlineSnapshotSettings.Default with
{
SnapshotUpdateStrategy = SnapshotUpdateStrategy.MergeTool,
MergeTool = DiffTool.VisualStudioCode,
};
}
}
You can also set the configuration per assert.
// InlineSnapshotSettings is a record, so you can use the "with" keyword to create a new instance
var settings = InlineSnapshotSettings.Default with
{
SnapshotUpdateStrategy = SnapshotUpdateStrategy.Overwrite,
};
InlineSnapshot.CreateBuilder()
.WithSettings(settings)
.Validate(data, "");
Environment variables
DiffEngine_Tool
: Set the default merge tool
Using helper methods
If you want to use helper methods before calling Validate()
, you need to decorate the methods with [InlineSnapshotAssertion]
and use [CallerFilePath]
and [CallerLineNumber]
.
Helper(""); // This string will be updated
[InlineSnapshotAssertion(nameof(expected))]
static void Helper(string expected, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber = -1)
{
InlineSnapshot.Validate(new object(), expected, filePath, lineNumber);
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- DiffEngine (>= 11.4.1)
- DiffPlex (>= 1.7.1)
- Meziantou.Framework.HumanReadableSerializer (>= 1.0.15)
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
- Microsoft.Win32.Registry (>= 5.0.0)
- System.Memory (>= 4.5.5)
- System.Text.Json (>= 7.0.2)
-
net6.0
- DiffEngine (>= 11.4.1)
- DiffPlex (>= 1.7.1)
- Meziantou.Framework.HumanReadableSerializer (>= 1.0.15)
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
-
net7.0
- DiffEngine (>= 11.4.1)
- DiffPlex (>= 1.7.1)
- Meziantou.Framework.HumanReadableSerializer (>= 1.0.15)
- Microsoft.CodeAnalysis.CSharp (>= 4.6.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Meziantou.Framework.InlineSnapshotTesting:
Package | Downloads |
---|---|
FunFair.Test.Common
FunFair Common Test Infrastructure for building xUnit tests on top of. |
|
Meziantou.Framework.InlineSnapshotTesting.Serializers.Argon
Serializer based on Argon for Meziantou.Framework.InlineSnapshotTesting |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.2.0 | 1,618 | 10/28/2024 |
3.1.1 | 346 | 10/27/2024 |
3.1.0 | 89 | 10/27/2024 |
3.0.11 | 1,076 | 10/20/2024 |
3.0.10 | 1,992 | 10/19/2024 |
3.0.9 | 536 | 10/18/2024 |
3.0.8 | 477 | 9/23/2024 |
3.0.7 | 5,773 | 8/1/2024 |
3.0.6 | 79 | 7/31/2024 |
3.0.5 | 2,997 | 6/24/2024 |
3.0.4 | 118 | 6/24/2024 |
3.0.3 | 89 | 6/24/2024 |
3.0.1 | 7,347 | 3/29/2024 |
3.0.0 | 13,563 | 1/6/2024 |
2.0.2 | 1,051 | 1/3/2024 |
2.0.1 | 2,514 | 12/29/2023 |
2.0.0 | 5,182 | 12/15/2023 |
1.0.28 | 2,923 | 12/6/2023 |
1.0.27 | 227 | 11/15/2023 |
1.0.26 | 199 | 9/29/2023 |
1.0.25 | 140 | 9/29/2023 |
1.0.24 | 313 | 7/22/2023 |
1.0.23 | 187 | 7/18/2023 |
1.0.22 | 180 | 7/10/2023 |
1.0.20 | 152 | 7/10/2023 |
1.0.19 | 362 | 5/31/2023 |
1.0.17 | 156 | 5/31/2023 |
1.0.16 | 151 | 5/30/2023 |
1.0.15 | 166 | 5/30/2023 |
1.0.14 | 148 | 5/27/2023 |
1.0.13 | 216 | 5/25/2023 |
1.0.12 | 156 | 5/25/2023 |
1.0.11 | 183 | 5/24/2023 |
1.0.9 | 219 | 4/28/2023 |
1.0.8 | 183 | 4/27/2023 |
1.0.7 | 176 | 4/25/2023 |
1.0.6 | 186 | 4/21/2023 |
1.0.5 | 205 | 4/12/2023 |
1.0.4 | 203 | 4/1/2023 |
1.0.3 | 241 | 3/24/2023 |
1.0.2 | 221 | 3/21/2023 |
1.0.1 | 218 | 3/19/2023 |
1.0.0 | 316 | 3/13/2023 |