Assert.Throws 仅在 Visual Studio Enterprise 和 Azure Devops 中部分涵盖

问题描述 投票:0回答:1

我的问题是我的代码中的所有 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");
    }
}

用彩色显示代码覆盖率表明 lamba 表达式仅被部分覆盖。 Code coverage

如何才能使覆盖率达到 100%?

c# visual-studio
1个回答
0
投票

删除不必要的 lambda。

public void throwsException()
{
    Assert.Throws<Exception>(TestMethod);
}
© www.soinside.com 2019 - 2024. All rights reserved.