Rcov 覆盖范围因 -xrefs 而发生巨大变化

发布于 2024-09-13 13:47:50 字数 1043 浏览 3 评论 0原文

我当前的 Ruby on Rails 项目通过 rcov 进行测试(具体来说,相关性 rcov,并且我们有相当高的标准(如果代码覆盖率小于 95%,则构建失败)。

我们使用以下命令来测试这一点:

rcov_cmd = "rcov --rails --text-summary \
            --include #{included_dirs} \
            --exclude #{excluded_dirs} \
            --aggregate #{coverage_dir}/coverage.data \
            --output #{coverage_dir} \

今天我在 rcov Homever 报告中发现了一些注册为绿色(已运行)的代码,我可以证明这一点。代码没有运行(我在函数的开头引发了一个异常,并且我的单元测试通过了)

我做了一些研究,发现了 rcov 的 --xrefs 标志,我认为它会添加每行的所有调用者rcov 报告。

我将 rcov 命令更改为:(

rcov_cmd = "rcov --rails --text-summary --xrefs \
        --include #{included_dirs} \
        --exclude #{excluded_dirs} \
        --aggregate #{coverage_dir}/coverage.data \
        --output #{coverage_dir} \

标志)。

我的测试覆盖率从 96% 变为 48%。

注意添加的 --xrefs -xrefs 改变 rcov 的分析方式(我认为它只会收集调用点信息)。这与第一个命令有何不同/更好? (我已经看到,如果单元测试失败,单元测试覆盖率会下降,并且我知道如果运行中出现错误,覆盖率百分比也会下降,但对我来说看起来不错)

My current Ruby on Rails project does testing via rcov (specifically, relevance rcov, and we have a pretty high standard (we fail the build if we have < 95% code coverage).

We use the following command to test this:

rcov_cmd = "rcov --rails --text-summary \
            --include #{included_dirs} \
            --exclude #{excluded_dirs} \
            --aggregate #{coverage_dir}/coverage.data \
            --output #{coverage_dir} \

Today I found some code that registers green (having run) in the rcov reports. Homever, I can prove that this code isn't getting run (I raise an exception in the beginning of the function, and my unit tests pass)

I did some research and found the --xrefs flag for rcov, which I thought would add all the callers for each line in the rcov reports.

I changed the rcov command to:

rcov_cmd = "rcov --rails --text-summary --xrefs \
        --include #{included_dirs} \
        --exclude #{excluded_dirs} \
        --aggregate #{coverage_dir}/coverage.data \
        --output #{coverage_dir} \

(notice the added --xrefs flag).

Instead of additional callsite information, I instead have my test coverage go from 96% to 48%.

Does --xrefs change the kind of analysis how rcov does? (I thought it would just gather callsite information). How is this different / better from the first command?
(I've seen the unit test coverage drop if there's a failing unit test, and I know that the coverage percentage can drop if there's an error in the run, but it looks good to me)

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

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

发布评论

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

评论(1

_蜘蛛 2024-09-20 13:47:50

来自 rcov 手册

--[no-]callsites
    Show callsites in generated XHTML report. (somewhat slower; disabled by default)
--[no-]xrefs
    Generate fully cross-referenced report. (includes --callsites)

来自 Rcov CallSiteAnalyzer 类

A CallSiteAnalyzer can be used to obtain information about:

    * where a method is defined ("defsite")
    * where a method was called from ("callsite")

通过此分析 rcov 可以提供更准确的覆盖信息,但执行时间较长。

From rcov manual:

--[no-]callsites
    Show callsites in generated XHTML report. (somewhat slower; disabled by default)
--[no-]xrefs
    Generate fully cross-referenced report. (includes --callsites)

From Rcov CallSiteAnalyzer Class

A CallSiteAnalyzer can be used to obtain information about:

    * where a method is defined ("defsite")
    * where a method was called from ("callsite")

Having this analyze rcov can provide more accurate coverage information in cost of longer execution.

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