OpenCover 显示 100% 的覆盖率,没有有效的测试

OpenCover shows 100% coverage with no valid tests

对于包含 6 个项目(class 库和 wcf 服务)的 visual studio 解决方案,我添加了一个包含一个测试的新测试项目,只有一行 Assert.AreEqual(1,1 ). OpenCover 显示 100% 覆盖率(100% 序列和 100% 分支)。

OpenCover.Console.exe -target:"nunit3-console.exe" "-targetargs:Services.nunit" -register:user -skipautoprops -mergebyhash

只有当我在测试中从其他项目实例化一个 class 时,覆盖率才下降到 0.1%。

所以看起来如果一个 dll 没有加载,OpenCover 无法计算它的代码覆盖率。

现在的问题是,如果添加了一个新的 class 库并且它从未在单元测试中实例化,OpenCover 会在计算覆盖率指标时忽略 dll。

这很重要,因为我们有一个分布式团队,开发人员可能只是创建一个 class 库,而从不为其编写测试。它最终会出现在代码审查中,但可以配置 OpenCover 来检测这种情况。

So looks like if a dll is not loaded, OpenCover cannot calculate its code coverage.

这是预期的行为

Now the question is if a new class library is added and it is never instantiated in a unit test, Will OpenCover just ignore the dll while calculating the coverage metrics.

它不会忽略它,运行时不会加载程序集,因此 OpenCover 看不到它。

It does eventually show up in code reviews, but can OpenCover be configured to detect this situation.

并非如此,但您可以编写一个测试来尝试加载其文件夹中的每个 .dll。这将导致它加载并且 OpenCover 将看到它(假设 pdb 可用并且过滤器允许它等等)