AssemblyInitialize 未在代码覆盖率中进行测量

发布于 2024-12-22 09:14:16 字数 243 浏览 0 评论 0原文

在使用代码覆盖率进行单元测试时,我遇到了一些奇怪的结果。

AssemblyInitialize函数中,我们做了一些初始化工作(如AutoMapperAbstractFactories),并且该函数被正确执行。

奇怪的是,代码覆盖率显示没有覆盖从 AssemblyInitialize 调用的函数。这是设计使然还是我在这里做错了什么?

I came across some strange results when using Code Coverage for our unit tests.

In the AssemblyInitialize function we do some initialization work (like AutoMapper, AbstractFactories) and this function is correctly executed.

The strange thing is that Code Coverage shows that there is no coverage for the functions that are called from AssemblyInitialize. Is this by design or am I doing something wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎歌 2024-12-29 09:14:16

我会选择按设计,它似乎太具体了,不能是其他任何东西。作为一个正在寻求对开源覆盖工具进行类似操作的人,这似乎很奇怪,因为这是一次意外,而且是一个非常不寻常的错误。

我内心的 TDD 纯粹主义者会说这是因为任何类型(程序集/类)的设置/拆卸实际上并不是测试本身的一部分,因此不应包含在覆盖范围内。相反,您应该对该代码进行单独的特定测试,而不是依赖于测试设置/初始化失败。

其他 .NET 工具(例如 dotCover)会通过测试进行覆盖,并且“可能”还会排除同时获得的结果运行此类设置;但这只是推测,而不是已知的事实。

I would go with as by-design it seems too specific to be anything other. As someone who is looking into doing similar for an open source coverage tool it seems odd for this to be an accident and would be a very unusual bug.

The TDD purist in me would say this is because the setup/teardown of any type (assembly/class) is not actually part of the test itself and so should not be included in coverage. You should instead have separate, specific tests for that code rather than rely on the test setup/initialization failing.

Other .NET tools (dotCover for one) does coverage by test and 'may' also exclude results gained whilst running such setups; this is conjecture rather than known fact though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文