C# VS/Can和x27中的单元测试;无法查看失败测试的完整错误消息

C# VS/Can和x27中的单元测试;无法查看失败测试的完整错误消息,c#,sql,visual-studio,unit-testing,C#,Sql,Visual Studio,Unit Testing,我目前正在为一个函数进行单元测试,该函数为merge命令返回一个SQL表达式。 我需要查看完整的错误消息,因为我需要查看实际函数的返回值 相反,我只得到了结果的一半 Test Name: deneme1 Test FullName: 'test name' Test Source: : line -1 Test Outcome: Failed Test Duration: 0:00:00 Test Name: deneme1 Test Outcome: Failed R

我目前正在为一个函数进行单元测试,该函数为merge命令返回一个SQL表达式。 我需要查看完整的错误消息,因为我需要查看实际函数的返回值

相反,我只得到了结果的一半

Test Name:  deneme1
Test FullName:  'test name'
Test Source:     : line -1
Test Outcome:   Failed
Test Duration:  0:00:00

Test Name:  deneme1
Test Outcome:   Failed
Result StackTrace:  
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
   at NUnit.Framework.Internal.Execution.SimpleWorkItem.PerformWork()

Result Message: 
Expected string length 182 but was 366. Strings differ at index 12.
  Expected: "MERGE INTO [intoTable] USING [sourceTable] ON [merge_conditio..."
  But was:  "MERGE INTO [tsttargetTable] USING (SELECT [tstsourceTable].[i..."
  -----------------------^


查看结果消息被切成两半。还有什么方法可以解决这个问题吗?

最简单的方法就是写出有问题的行,然后查看单元测试的“附加输出”。单击打开此结果的其他输出

我假设您使用的是
nunitv3
或更高版本。在这种情况下,使用

TestContext.WriteLine("some string");
写出额外的一行。其他测试框架可能支持
Console.WriteLine
或它们自己的自定义机制来编写输出

编辑(添加示例单元测试)。 因此,假设您有一个单元测试,如下所示:

[Test]
public void MyTest()
{
    var systemUnderTest = new SystemUnderTest();
    var expected = "INSERT INTO blah blah";
    var actual = systemUnderTest.DoThingThatGetsASqlString();
    TestContext.WriteLine($"The full SQL string was: '{sqlString}'");

    Assert.AreEqual(expected, actual);
}

是的,我正在使用NUnit v3,不知道把
TestContext.WriteLine(“一些字符串”)放在哪里