Assert equality on collections: can the error message describe the difference between the two collections? #2149
-
I am somewhat unhappy with the exception text for the equality assertion of collections.
I get the following error message (within Visual Studio):
With that message, it is hard to see the difference between the two collections. Can I improve the message myself or should I write a customized assert method? For simple cases, I'd like to get a clue on the difference of the two collections... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This was recently fixed: f4be18e?w=1 Example: [Fact]
public void ExactArraySize_DifferenceNearStart()
{
var expectedMessage =
"Assert.Equal() Failure" + Environment.NewLine +
" ↓ (pos 1)" + Environment.NewLine +
"Expected: [1, 2, 3, 4, 5]" + Environment.NewLine +
"Actual: [1, 99, 3, 4, 5]" + Environment.NewLine +
" ↑ (pos 1)";
var ex = Record.Exception(
() => Assert.Equal(
new List<int> { 1, 2, 3, 4, 5 },
new List<int> { 1, 99, 3, 4, 5 }
)
);
Assert.NotNull(ex);
Assert.Equal<object>(expectedMessage, ex.Message);
} |
Beta Was this translation helpful? Give feedback.
This was recently fixed: f4be18e?w=1
Example: