Nzr.Snapshot.Xunit.Extensions
1.0.5
See the version list below for details.
dotnet add package Nzr.Snapshot.Xunit.Extensions --version 1.0.5
NuGet\Install-Package Nzr.Snapshot.Xunit.Extensions -Version 1.0.5
<PackageReference Include="Nzr.Snapshot.Xunit.Extensions" Version="1.0.5" />
paket add Nzr.Snapshot.Xunit.Extensions --version 1.0.5
#r "nuget: Nzr.Snapshot.Xunit.Extensions, 1.0.5"
// Install Nzr.Snapshot.Xunit.Extensions as a Cake Addin #addin nuget:?package=Nzr.Snapshot.Xunit.Extensions&version=1.0.5 // Install Nzr.Snapshot.Xunit.Extensions as a Cake Tool #tool nuget:?package=Nzr.Snapshot.Xunit.Extensions&version=1.0.5
Nzr.Snapshot.Xunit.Extensions
Nzr.Snapshot.Xunit.Extensions
is a simple extension library for integrating Snapshooter with xUnit. It enables custom folder organization for snapshots based on test attributes and allows for flexible snapshot management in unit tests.
Features
- Custom Folder Organization: Automatically organize snapshots into custom folders based on the
SnapshotFolder
attribute applied to xUnit test methods. - Class Name Exclusion: Optionally exclude the class name from the snapshot file path.
Installation
You can install Nzr.Snapshot.Xunit.Extensions
via NuGet Package Manager:
dotnet add package Nzr.Snapshot.Xunit.Extensions
Or, via the NuGet package page.
Usage
To use this package, simply include it in your xUnit test project and apply the extension methods to match the snapshots of objects during tests.
Example Usage
using FluentAssertions;
using Snapshooter;
using Nzr.Snapshot.Xunit.Extensions;
public class SnapshotTests
{
[Fact]
public void Match_Without_SnapshotFolderAttribute_Should_Snapshot_Folder_In_The_Same_Folder()
{
// Arrange
var currentResult = new { City = "Nova Lima", CreatedAt = DateTimeOffset.Now };
// Assert
currentResult.Should().Match();
}
[SnapshotFolder("SnapshotExtensions")]
[Fact]
public void Match_With_SnapshotFolderAttribute_Should_Snapshot_Folder_In_Specified_Folder()
{
// Arrange
var currentResult = new { City = "Lisbon", CreatedAt = DateTimeOffset.Now };
// Assert
currentResult.Should().Match();
}
[SnapshotFolder("Shared", excludeClassName: false)]
[Fact]
public void Match_With_SnapshotFolderAttribute_Keeping_ClassName_Should_Snapshot_Folder_In_Specified_Folder()
{
// Arrange
var currentResult = new { City = "Berlin", CreatedAt = DateTimeOffset.Now };
// Assert
currentResult.Should().Match();
}
}
SnapshotFolderAttribute
The SnapshotFolderAttribute
is used to define custom folder paths for your snapshots.
You can optionally specify whether to exclude the class name from the snapshot file name.
Parameters:
Name
: Specifies the folder name for snapshots.ExcludeClassName
: Optional boolean to exclude the class name from the snapshot filename.
[SnapshotFolder("FolderName", excludeClassName: true)]
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Contributing
We welcome contributions! If you'd like to contribute to this project, please fork the repository and submit a pull request. Please ensure that your code passes all tests and includes relevant documentation for new features or changes.
Steps for Contribution
- Give a start for this repository!
- Fork the repository.
- Clone the forked repository to your local machine.
- Create a new branch.
- Implement your changes.
- Run tests to ensure everything works.
- Commit your changes and create a pull request.
Acknowledgements
- Snapshooter for snapshot testing.
- xUnit for providing a great testing framework.
- The open-source community for their contributions and feedback.
For more information on how to use this project, please refer to the documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Snapshooter.Xunit (>= 0.14.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.