Release Notes: October 3, 2021
xUnit.net 2.4.2 Pre-Release (build 12)
BUG: Fixed an issue where
DisposalTracker was not properly made thread
safe. This typically only surfaced in acceptance tests, but was also an edge case for the .NET team.
The assertion library is now nullable enabled.
Argument formatting for
float values is now done to 9 digits of precision, and formatting
double values is now done to 17 digits of precision. This better matches the maximum
numeric types in .NET. This may result in displayed values being slightly different than the
previous default formatting allowed (both for argument formatting and assertion error messages).
Improved the output of expected and actual values when they're multi-line, so that they are properly
indented when displayed in failure messages.
Formatted dictionary entries (in arguments and assert messages) should be easier now to copy/paste as
usable C# code.
An overload of
Assert.All was added which will pass not only the item to the verification
lambda but also the item's index in the collection.
Assert.Equal(float expected, float actual, float tolerance).
Assert.Equal(double expected, double actual, double tolerance).
Assert.Equal(double expected, double actual, int precision, MidpointRounding rounding).
Assert.Equal<T>(T expected, T actual) to include the mismatched item index
actual are collections.
Improve the list of whitespace recognized by
Assert.Equal(string? expected, string? actual, bool
ignoreCase = false, bool ignoreLineEndingDifferences = false, bool ignoreWhiteSpaceDifferences = false)
to include: TABULATION (U+0009), SPACE (U+0020), NO-BREAK SPACE (U+00A0), OGHAM SPACE MARK (U+1680), MONGOLIAN
VOWEL SEPARATOR (U+180E), EN QUAD (U+2000), EM QUAD (U+2001), EN SPACE (U+2002), EM SPACE (U+2003), THREE-PER-EM
SPACE (U+2004), FOUR-PER-EM SPACE (U+2005), SIX-PER-EM SPACE (U+2006), FIGURE SPACE (U+2007), PUNCTUATION SPACE
(U+2008), THIN SPACE (U+2009), HAIR SPACE (U+200A), ZERO WIDTH SPACE (U+200B), NARROW NO-BREAK SPACE (U+202F),
MEDIUM MATHEMATICAL SPACE (U+205F), IDEOGRAPHIC SPACE (U+3000), and ZERO WIDTH NO-BREAK SPACE (U+FEFF).
Assert.Empty now shows the contents of the collection on failure.
Assert.Equivalent(object? expected, object? actual, bool strict = false). The following
rules are used to determine equivalence:
In the case of collections and complex types, the comparison are deep: that is, every value in the collection or
every public property/field gets an equivalence test against it. If the value in the collection or complex object
is itself a collection or complex object, then the above process repeats. Circular references in either the expected
or actual values (regardless of how deep the loop goes) will be reported as failures. For examples of usage, please
see the unit
tests, as they are fairly comprehensive.
If one of the values is
null, they are only equivalent if they are both
If the values are value types (or
Object.Equals is called to
perform the equivalence test. Note that these values must be of the same type (for example, a value of
Int32 is not equivalent to a value of
If the values are collections, then each value in the expected collection is compared against all the values
in the actual collection to find one that's equivalent. If an equivalent value is found in the actual collection,
it is removed from the actual collection (so it can only match as equivalent one time). This process repeats for
every value in the expected collection. If any value in the expected collection cannot find an equivalent in the
actual collection, then an error is reported. If
strict is true, then any values left over in the actual
collection will also cause an error to be reported.
If none of the other tests were used, then the expected and actual values are treated as a complex type.
For every public property or field in the expected object, an equivalent public property or field must exist
in the actual object with an equivalent value; any unmatched value on the expected object will cause an error
to be reported. If
strict is true, then any public property/field that wasn't matched against
a value on the expected object will also cause an error to be reported.
Assert.Fail(message). Previously developers would be forced to use something like
Assert.Multiple(params Action checks) which allows the developer to run several assertions
as individual lambdas, and collect up all the failures into a single failure. If there is only a single failure,
it will show as normal; if there are multiple failures, a new message shows that there were multiple failures,
which includes all the failure messages and associated stack traces.
Assert.Raises and friends no longer require the event type to be derived from
Assert.Single now shows the item count of the collection on failure.