如何在不降低代码覆盖率的情况下忽略一些单元测试?

发布于 2024-12-07 02:11:04 字数 242 浏览 6 评论 0原文

我有一门与数据库对话的课程。

我有我的集成测试,它与 Db 对话并断言相关更改。但我希望在提交代码时忽略这些测试,因为我不希望稍后自动调用它们。 (只是为了开发时间,我现在使用它们)

当我放置 [Ignore] 属性时,它们不会被调用,但代码覆盖率会大大减少。

有没有办法保留这些测试但不让它们自动运行 在构建机器上,事实上它们被忽略了 不影响代码覆盖率?

I have one class which talks to DataBase.

I have my integration-tests which talks to Db and asserts relevant changes. But I want those tests to be ignored when I commit my code because I do not want them to be called automatically later on.
(Just for development time I use them for now)

When I put [Ignore] attribute they are not called but code-coverage reduces dramatically.

Is there a way to keep those tests but not have them run automatically
on the build machine in a way that the fact that they are ignored does
not influence code-coverage percentage?

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

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

发布评论

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

评论(4

忆悲凉 2024-12-14 02:11:04

无论您使用什么代码覆盖工具,很可能都有某种 CoverageIgnoreAttribute 或类似的东西(至少我用过的那些),所以您只需将其放在从这些单元测试中调用的方法块上就可以了。

Whatever code coverage tool you use most likely has some kind of CoverageIgnoreAttribute or something along those lines (at least the ones I've used do) so you just place that on the method block that gets called from those unit tests and you should be fine.

念三年u 2024-12-14 02:11:04

你的要求似乎没有意义。代码覆盖率是通过执行测试并记录执行的语句/条件等来衡量的。如果禁用测试,则不会执行任何操作,并且代码覆盖率会下降。

What you request seems not to make sense. Code-Coverage is measured by executing your tests and log which statements/conditions etc. are executed. If you disable your tests, nothing get executed and your code-coverage goes down.

嘦怹 2024-12-14 02:11:04

TestNG 有组,因此您可以指定仅自动运行某些组,并让其他组在其之外使用。您没有指定单元测试框架,但它可能有类似的东西。

TestNG has groups so you can specify to only run some groups, automatically and have the others for usage outside of that. You didn't specify your unit testing framework but it might have something similar.

撞了怀 2024-12-14 02:11:04

我不知道这是否适用于你的情况。但我自然而然地想到了一种设置,其中有两个解决方案文件(.sln),一个带有单元/集成测试,一个没有。这两个解决方案共享相同的代码和项目文件,但您的开发/测试解决方案包括单元测试(在编译时构建和运行),而另一个解决方案则不包括。两种解决方案都应受源代码控制,但只有没有单元测试的解决方案由构建服务器构建。

这种设置不需要您更改现有代码(太多)。我更喜欢重写代码来适应您的测试设置。

I do not know if this is applicable to your situation. But spontaneously I am thinking of a setup where you have two solution files (.sln), one with unit/integration tests and one without. The two solutions share the same code and project files with the exception that your development/testing solution includes your unit tests (which are built and run at compile time), and the other solution doesn't. Both solutions should be under source control but only the one without unit tests are built by the build server.

This kind of setup should not need you to change existing code (too much). Which I would prefer over rewriting code to fit your test setup.

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