Xunit.AssertMessages 2.7.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Xunit.AssertMessages --version 2.7.1
NuGet\Install-Package Xunit.AssertMessages -Version 2.7.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xunit.AssertMessages" Version="2.7.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Xunit.AssertMessages --version 2.7.1
#r "nuget: Xunit.AssertMessages, 2.7.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Xunit.AssertMessages as a Cake Addin
#addin nuget:?package=Xunit.AssertMessages&version=2.7.1

// Install Xunit.AssertMessages as a Cake Tool
#tool nuget:?package=Xunit.AssertMessages&version=2.7.1

xunit.AssertMessages

NuGet version (Xunit.AssertMessages)

Adds assert messages to all xunit Assert calls.

Usage

Get the nuget package here.

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 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.8.0 75 4/30/2024
2.7.1 105 4/19/2024
2.7.0 1,252 2/17/2024
2.6.3 10,050 12/9/2023
2.6.2 606 11/21/2023
2.5.2 606 9/25/2023
2.5.1 407 8/28/2023
2.5.0 140 8/27/2023
2.4.2 8,146 5/9/2023
2.4.1 154 5/7/2023
2.4.0 70,706 9/10/2022

v.2.7.1
- Updated to xUnit 2.7.1
v.2.7.0
- Updated to xUnit 2.7.0.
v.2.6.3
- Updated to xUnit 2.6.3.
v.2.6.2
- Updated to xUnit 2.6.2.
v.2.5.2
- Updated to xUnit 2.5.1.
v.2.5.1
- Added strong name signing.
v.2.5.0
- Updated to xUnit 2.5.0.
v.2.4.1
- Added nullability annotations.
- Fixed ambigous overload for Assert.Equal(string, string,...).
v.2.4.2
- Fixed more ambigous overload for Assert.Equal(string, string,...).