Xunit.AssertMessages
2.4.0
See the version list below for details.
dotnet add package Xunit.AssertMessages --version 2.4.0
NuGet\Install-Package Xunit.AssertMessages -Version 2.4.0
<PackageReference Include="Xunit.AssertMessages" Version="2.4.0" />
<PackageVersion Include="Xunit.AssertMessages" Version="2.4.0" />
<PackageReference Include="Xunit.AssertMessages" />
paket add Xunit.AssertMessages --version 2.4.0
#r "nuget: Xunit.AssertMessages, 2.4.0"
#:package Xunit.AssertMessages@2.4.0
#addin nuget:?package=Xunit.AssertMessages&version=2.4.0
#tool nuget:?package=Xunit.AssertMessages&version=2.4.0
xunit.AssertMessages
Adds assert messages to all xunit Assert calls.
Usage
All methods are static on the AssertM class.
Simply add the nuget package to your test project and add
// Alias the assert to quickly migrate existing code to use AssertM.
using Assert = XunitAssertMessages.AssertM;
to your usings. (For an example see the xUnitMessages.Example project.)
All aserts will work identical to before but will now have an optional additional
parameter that adds a custom message. E.g.
int expectedShippingDelay = 10;
int actualShippingDelay = 9;
Assert.Equal(expectedShippingDelay, actualShippingDelay, "The shipping delay is incorrectly configured.");
will output
Xunit.Sdk.XunitException
The shipping delay is incorrectly configured.
You can includ the original message from xUnit via {xMsg}
Example:
Assert.Equal(10, 9, "This is so wrong. {xMsg}");
use double curly brackets with an interpolated string
Assert.Equal(10, 9, $"{9} is so wrong. {{xMsg}}");
Motivation
When working with tools like SpecFlow or other behaviour driven frameworks the result of a test is often not read by a programmer but by domain experts. In that scenario an error message like
The vat was calculated incorrectly, the test expects 24.40$ but the calculated value is 34.40$
is a lot more helpful than
Expected: 2440 Actual: 3440
.
The default xunit.assert package does not support custom messages except on the Assert.True
and Assert.False methods, but (re-)writing tests with only those two methods is a lot of overhead.
Technical details
Please note the following technical details:
- The type of exception thrown by assert will always be
Xunit.Sdk.XunitExcepion - The original xunit.assert exception will not be included as inner exception, instead the original inner exception will be kept.
- If using
{xMsg}to include the original xunit.assert exception message a newline will be prepended. (As most exceptions will already include newlines in their message)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- xunit.assert (>= 2.4.2 && < 2.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Xunit.AssertMessages:
| Repository | Stars |
|---|---|
|
dafny-lang/dafny
Dafny is a verification-aware programming language
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.9.2 | 57,619 | 10/16/2024 |
| 2.9.0 | 6,243 | 7/13/2024 |
| 2.8.1 | 1,024 | 5/26/2024 |
| 2.8.0 | 955 | 4/30/2024 |
| 2.7.1 | 477 | 4/19/2024 |
| 2.7.0 | 4,368 | 2/17/2024 |
| 2.6.3 | 49,037 | 12/9/2023 |
| 2.6.2 | 2,497 | 11/21/2023 |
| 2.5.2 | 1,255 | 9/25/2023 |
| 2.5.1 | 888 | 8/28/2023 |
| 2.5.0 | 496 | 8/27/2023 |
| 2.4.2 | 14,152 | 5/9/2023 |
| 2.4.1 | 525 | 5/7/2023 |
| 2.4.0 | 188,935 | 9/10/2022 |