5

我在 Jenkins 上设置了 gcov 代码覆盖工具。

这很好用,但我很难理解输出颜色代码。每条线的“命中”数是正确的,但有些线是绿色的,而另一些是红色的,我不知道为什么。

例子 :

在此处输入图像描述

请注意,setYear 方法全是绿色的,并且调用了 13 次(在屏幕截图中可以看到 setDateAAMMJJ 中的 ctor + 12 次)

4

2 回答 2

2

如果您查看cobertura-plugingithub上的源代码,您会看到:

table.source tr.coverPart td.hits, table.source tr.coverNone td.hits {
    background-color: #fdd;
    font-weight: bold;
}

table.source tr.coverPart {
    background-color: #ffd;
}
  • #fdd是红色,
  • #ffd是黄色的

您应该能够使用浏览器的“开发者工具”或“检查器”功能来查看应用了哪个类。

这是什么意思?

The yellow on the far left means the source code is covered partly, that means you probably don't have 100% coverage in the functions that are being called.

Another case I can think of (pure speculation at this point) is that some optimization is mangling your statement coverage; check your compilation flags.

If you kept the data (lcov files), you should be able to use genhtml to generate a report and compare.

于 2015-03-13T02:41:37.093 回答
1

Don't know if this applies for you but it seems relevant. In my case it is red because branch cover is not 100%. When generating an xml with gcovr it also adds branch cover data.

It is possible to cover all the lines but not cover all the branches. Im having all kinds of problems with the branch cover.

Some are described in these posts.

为什么 gcc 4.1 + gcov 报告 100% 的分支覆盖率,而更新的(4.4、4.6、4.8)报告“p = new class;”为 50% 线?

gcov 报告的析构函数中的分支是什么?

仍在寻找解决此类问题的方法..

于 2017-03-17T14:35:22.517 回答