将代码覆盖率链接到版本控制

发布于 2024-10-16 01:39:44 字数 278 浏览 2 评论 0原文

在提交更改之前,我想确保所有更改都已通过代码覆盖率报告自动或手动进行测试,但有很多遗留代码没有自动化测试,也不会会受到我的改变的影响。

是否有一种工具可以通过代码覆盖率报告交叉引用版本控制工具的差异,并确保已更改的所有内容都已运行?

我意识到,通过代码覆盖率,这可能会给人一种错误的安全感,而对于这样的事情,甚至更是如此,但我认为这是值得尝试的。我使用 git 和 PHP - 我使用 XCache 的代码覆盖率界面来浏览我运行的内容,它很有用,但如果某些东西可以在 git 提交或推送时自动运行,那就太好了。

Before I commit a change, I'd like to be sure that all of it has been tested, either automatically or manually with a code coverage report, but there is lots of legacy code that doesn't have automated tests, and won't be affected by my changes.

Is there a tool that can cross reference a diff from a version control tool with a code coverage report and make sure everything that has been changed has been run?

I realise that with code coverage, this may give a false sense of security, and with something like this, even more so, but I think it would be worth trying. I use git and PHP - I've used XCache's code coverager interface to browse what I have run, and it's useful, but it would be great if something could run automatically at git commit or push time.

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

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

发布评论

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

评论(2

海之角 2024-10-23 01:39:44

对于 git 差异,有一个名为 diff-cover 的工具,它可以检查覆盖范围。它获取 Cobertura XML 覆盖率报告并与 git diff 的输出进行比较。然后它报告差异中各行的覆盖信息。

给定正确的覆盖 xml 文件,您可以使用此命令来检查与 master 分支相比的更改的覆盖范围:

$ diff-cover coverage.xml

与 CI 服务器集成也非常简单,只要它能够提供您需要比较的提交,例如 Jenkins 中的 $GIT_PREVIOUS_COMMIT

For git diffs, there is a tool named diff-cover, which can check coverage. It takes Cobertura XML coverage reports and compares with the output of git diff. It then reports coverage information for lines in the diff.

Given the proper coverage xml file, you can use this command to check the coverage of your changes compared to the master branch:

$ diff-cover coverage.xml

It is also pretty simple to integrate with a CI server, as long as it can provide you with the commit you need to compare with, like $GIT_PREVIOUS_COMMIT in Jenkins.

怕倦 2024-10-23 01:39:44

您可以设置一个持续集成构建服务器(有很多优秀的免费构建服务器)。构建步骤之一是运行代码覆盖率。您可以将其设置为忽略遗留代码并仅计算非遗留代码的覆盖率。然后,您将其设置为如果覆盖率 < > 则构建失败。 xx%。或者,如果覆盖率比之前的版本有所下降,甚至会失败。

You could set up a continuous integration build server (there are lots of excellent, free build servers). One of the build steps would be running code coverage. You could set it up to ignore legacy code and calculate coverage only for non-legacy code. Then you set it up to fail the build if coverage < xx%. Or even fail if coverage % decreases from the previous build.

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