The majority of this release is the overhaul of the assertion library, for message consistency and
clarity. This also included a pass to remove unsafe double-enumeration and improve performance when
asserting against enumerables. In most cases, the display for enumerable should be at least as good
as previous releases; however, there is a case where we don't know whether an IEnumerable
implementation is safe for either re-enumeration and/or complete enumeration (since an enumerable
can in theory enumerate forever). In those cases, you may see enumerables represented with just
a [ยทยทยท]
rendering (especially in theory data parameter rendering).
For a list of some example changes, see this list of comparisons between assertion messages in 2.4.2 and 2.5.0.
This release also brings in xunit.analyzers
version
1.2.0-pre.7
.
TimeSpan
(supported on all frameworks)BigInteger
(supported on all frameworks except .NET Framework)DateOnly
(supported on .NET 6 and later)TimeOnly
(supported on .NET 6 and later)DiagnosticMessage
class now implements ToString()
and outputs the
message, for simpler debugging for extensibility authors.
Assert.Contains
behaved unexpectedly with dictionaries and sets. This is
because these both have custom logic for their Contains
function that is
contrary to our normal container comparison logic. Their constructors allow you to pass
key comparers; normally, comparers are only used when looking things up. This fixes
this so it will have consistent behavior with the framework.
xunit/xunit#2671
Assert.Equal(DateTime, DateTime)
and
Assert.Equal(DateTimeOffset, DateTimeOffset)
overloads.
Assert.Equal(DateTime, DateTime, TimeSpan)
and
Assert.Equal(DateTimeOffset, DateTimeOffset, TimeSpan)
overloads. They specify a
precision (in time span) that the two times must be within one another. This precision works
in both directions: expected earlier than actual, or expected later than actual.
xunit/xunit#2588
Assert.Equal(T, T, Func<T, T, bool> comparer)
and
Assert.NotEqual(T, T, Func<T, T, bool> comparer)
overloads. This allows the
dev to write an inline comparison function rather than being forced to implement one of the
equality interfaces (like IEqualityComparer<T>
) in a separate class.
xunit/xunit#2692
Assert.Equal()
for strings has a new flag: ignoreAllWhiteSpace
indicates
that all whitespace should be ignored. The difference between this and ignoreWhiteSpaceDifferences
is that the latter requires at least one piece of whitespace. Examples:Assert.Equal("a b", "ab", ignoreWhiteSpaceDifferences: true);
Assert.Equal("a b", "ab", ignoreAllWhiteSpace: true);
xunit/xunit#2440
Assert.Equivalent
with two equal values that are of different (but compatible)
types previous failed. After discussion with the community, this was fixed to now pass.
Example of code that now passes that previously failed: Assert.Equivalent(12, 12L);
Poll on Mastodon
Assert.Throws<ArgumentException>()
threw an
exception when you passed a null parameter name, despite being legal in ArgumentException
.
xunit/xunit#2396
Assert.Equivalent
was not appropriately handling reference
types inside of value types.
xunit/xunit#2431
Assert.Equivalent
was inadvertently comparing non-public
properties.
xunit/xunit#2621
Assert.Equivalent
was incorrectly trying to compare
indexer properties (which are more like functions than properties). Now, this will skip
indexer properties.
xunit/xunit#2698
type[*]
correctly.
xunit/xunit#2534
Assert.Equal(float, float, int precision)
and
Assert.Equal(float, float, int precision, MidpointRounding)
.
xunit/xunit#2393
IAssertionException
was accidentally always public,
even when importing via source and setting `XUNIT_VISIBILITY_INTERNAL`.
xunit/xunit#2703