简体   繁体   English

Visual Studio Runner中的xUnit错误消息

[英]xUnit error messages in the Visual Studio Runner

I am using xUnit theory to group related input to the same test, such as this: 我正在使用xUnit理论将相关输入分组到同一测试中,例如:

[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. 但是,如果第一次失败,我只能看到ExpectedOutput和实际输出。 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. 我意识到我可以将ExpectedOutput更改为唯一的内容,但是测试多个都提供相同输出的输入并非没有道理。 Is there no way to display in visual studios testrunner what input caused the test to fail? 有没有办法在Visual Studio Testrunner中显示什么输入导致测试失败?

您可以使用具有用户消息参数的Assert.True:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM