[Test]
public void AssertMultipleTest()
{
try
{
Assert.Multiple(() =>
{
Assert.That(true, Is.False);
Assert.That(7, Is.Zero);
});
}
catch (Exception e)
{
Log.Save(e.ToString());
throw;
}
}
测试功能生成以下报告:
One or more failures in Multiple Assert block:
1) Expected: False
But was: True
2) Expected: 0
But was: 7
如何在catch-block中获取相同的报告?现在我只得到以下内容:
Tests.AssertMultipleTest - NUnit.Framework.MultipleAssertException: One or more failures in Multiple Assert block:
at NUnit.Framework.Assert.Multiple(TestDelegate testDelegate)
at AnonymizeDataTests.Tests.AssertMultipleTest() in C:\Development\TestClass.cs:line 76
答案 0 :(得分:0)
也许我找到了解决问题的方法。我没有在测试中记录错误,而是跳过整个try-catch-block并将结果记录在TearDown中。像这样:
[TearDown]
public void TearDown()
{
if (TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Passed)
{
Log.Save(TestContext.CurrentContext.Result.Message);
}
}
[Test]
public void AssertMultipleTest()
{
Assert.Multiple(() =>
{
Assert.That(true, Is.False);
Assert.That(7, Is.Zero);
});
}