New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce Snapshot Testing Like Jest #1727
Comments
I recently made a library for exactly this purpose. |
@RehanSaeed |
this is also referred to as approval tests. Random impl I hit when I googled |
There are two main downsides of the library I made which could be solved by integrating snapshots into xunit.
By having snapshotting integrated into xunit you can improve the user experience of managing snapshots greatly. The xunit runner could take in parameters to update snapshots like jest does. The xunit VS plugin could provide an easy way to update and manage snapshots. The xunit runner/plugin could show a diff with colours for a better user experience. |
I am not speaking against this proposal, merely offering additional information for consideration...
Snapshooter:
By using a diff tool of my choice I get the experience I want.
I'm not against this, it just doesn't make sense for how I maintain my snapshot tests, which is in Visual Studio with Test Explorer. The only time my snapshot tests get run from the command line is when they are already deployed somewhere (or when I want to test that they will run correctly from the command line). I do not (and probably would not since I've already been there with Jest) maintain snapshot files from the command line. I recommend the Snapshooter design over the Jest design for updating/managing snapshots. I've used Jest snapshot testing extensively in the past, with a full suite of integration tests, and while Snapshooter is very much based on Jest snapshot testing, I prefer the Snapshooter design when it comes to updating/managing snapshots. Jest update process:
Snapshooter update process:
The snapshooter process may sound like more work but in practice I have very much preferred it. Complaints I have that I would like to see resolved in an xUnit implementation Two of my biggest complaints with Snapshooter:
In summary: I support this proposal, but I do not think matching Jest design exactly is the best approach. I think Snapshooter is a great reference point and would like to see the Snapshooter design for updating/maintaining snap files persued instead of the Jest design. Finally, I would like to see some additional features/niceties in an xUnit implementation that are lacking in Snapshooter. If any of this didn't make sense please ask questions and I'll try to clarify. |
try https://github.com/VerifyTests/Verify
Verify has a variety of approaches to managing snapshots
Verify can ignore a type, a member by name, a member expression, https://github.com/VerifyTests/Verify/blob/main/docs/serializer-settings.md#ignoring-a-type
Verify support all the common diff tools https://github.com/VerifyTests/DiffEngine#supported-tools
Verify give full control over this https://github.com/VerifyTests/Verify/blob/main/docs/naming.md#derivepathinfo |
I raised this some time ago before I was aware of Verify which I think solves this issue albeit using a second NuGet package. |
IMO this does not need to be included in Xunit. so probably remove it from the v3 release |
@RehanSaeed in that case should this be closed? |
@bradwilson can u remove the v3 label |
The Jest JavaScript test framework has a feature called snapshot testing. It would be cool for xUnit to add this feature, especially as Blazor components are coming and snapshot testing is great for testing renderred HTML output.
The text was updated successfully, but these errors were encountered: