我的问题是我的代码中的所有 Assert.Throws 仅显示为部分覆盖。
给出以下代码,覆盖率不是预期的 100%,而是 89%。
using System;
using NUnit.Framework;
namespace Test;
[TestFixture]
public class Test1
{
[Test]
public void throwsException()
{
Assert.Throws<Exception>(() => TestMethod());
}
private static void TestMethod()
{
throw new Exception("exception");
}
}
如何才能使覆盖率达到 100%?
删除不必要的 lambda。
public void throwsException()
{
Assert.Throws<Exception>(TestMethod);
}