hvidgaard
hvidgaard

Reputation: 495

xUnit error messages in the Visual Studio Runner

I am using xUnit theory to group related input to the same test, such as this:

[Theory]
[InlineData("fg00123 kj 56", "123")]
[InlineData("123", "123")]
public void NormalizeString(string input, string expectedOutput) {
    Assert.Equal(expectedOutput, MethodToTest(input));
}

But if the first fails I can only see the expectedOutput and actual output. I realize that I can change the expectedOutput to something unique, but it is not unreasonable to test several inputs that all give the same output. Is there no way to display in visual studios testrunner what input caused the test to fail?

Upvotes: 1

Views: 2217

Answers (1)

robi-y
robi-y

Reputation: 1717

You can use Assert.True which has a user message parameter:

var actualOutput = MethodToTest(input); Assert.True(expectedOutput==actualOutput, string.Format("for input {0} expected {1} but got {2}", input, expectedOutput, actualOutput));

Upvotes: 4

Related Questions