c++ - 不存在的行包含在 Visual Studio 2017 中的动态代码覆盖率分析中
问题描述
在这篇文章之后,我正在尝试在 Visual Studio 2017 for C++ 中测试动态代码覆盖率。但是,覆盖范围似乎正在执行根本不在程序中的行。这是我用来测试覆盖率的简单程序:
ConsoleApplication3.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Running..." << endl;
if (false) {
cout << "shouldn't print" << endl;
}
#ifdef _WIN32
cout << "Running in WIN" << endl;
#else
cout << "Running in LIN" << endl;
#endif
}
首先我使用/PROFILE
标志(在解决方案资源管理器中,然后右键单击项目Properties > Linker > Advanced > Profile > set to "Yes (/PROFILE)"
。要运行我的测试,我只需要执行ConsoleApplication3.exe
,所以按照说明进行操作:
codecoverage collect /session:qwerty /output:mytest.coverage .\Debug\ConsoleApplication3.exe
codecoverage shutdown /session:qwerty
codecoverage analyze /output:mytestCoverage.xml .\mytest.coverage
注意:根据我上面分享的帖子,没有提到您需要包含.exe
作为参数。这意味着您可以开始收集,然后在收集开始后运行您的测试。然而,这只是给我留下了一个空的报告,我发现这实际上是生成一个真实的报告。接下来,我将生成的mytest.coverage
文件转换为.xml
格式。打开mytestCoverage.xml
我看到以下内容:
mytestCoverage.xml
<?xml version="1.0" encoding="UTF-8"?>
<results>
<modules>
<module lines_not_covered="1" lines_partially_covered="0" lines_covered="6" blocks_not_covered="3" blocks_covered="10" line_coverage="85.71" block_coverage="76.92" id="A62F1CFD667E27408B95EED542B0A03801000000" path="consoleapplication3.exe" name="consoleapplication3.exe">
<functions>
<function lines_not_covered="1" lines_partially_covered="0" lines_covered="6" blocks_not_covered="3" blocks_covered="10" line_coverage="85.71" block_coverage="76.92" id="6832" name="_main" type_name="">
<ranges>
<range end_column="0" end_line="6" start_column="0" start_line="6" covered="yes" source_id="0" />
<range end_column="0" end_line="7" start_column="0" start_line="7" covered="yes" source_id="0" />
<range end_column="0" end_line="9" start_column="0" start_line="9" covered="yes" source_id="0" />
<range end_column="0" end_line="10" start_column="0" start_line="10" covered="no" source_id="0" />
<range end_column="0" end_line="14" start_column="0" start_line="14" covered="yes" source_id="0" />
<range end_column="0" end_line="19" start_column="0" start_line="19" covered="yes" source_id="0" />
<range end_column="0" end_line="15732480" start_column="0" start_line="15732480" covered="yes" source_id="0"/>
</ranges>
</function>
</functions>
-
<source_files>
<source_file id="0" path="c:\users\sakeeb_hossain\source\repos\consoleapplication3\consoleapplication3.cpp" checksum="87CCE2DD760287BB1A6A3CCF2BF8B930" checksum_type="MD5" />
</source_files>
</module>
</modules>
</results>
看看最后一个<range>
标签。我的问题是它来自哪里以及如何摆脱它(当然除了手动编辑)?
解决方案
推荐阅读
- sql - SQL Server 加入聚合函数的结果
- featuretools - 使用 featuretool,如何单独使用 dfs 原语?
- java - kinesis 分析 flink 写入 parquet 文件
- java - java.sql.SQLException:关闭结果集:下一个
- list - 如何对列表进行排序
在 Dart 中以空对象结尾 - functional-programming - 如何将 Lisp/Scheme/Racket 符号放在末尾?
- azure - 如何在 Istio 中配置 Azure 应用网关
- python - 执行通常包含 '\;' 的 tmux 命令 使用 subprocess.run
- gcc - cmake - 预处理整个项目并将输出存储在文件中
- button - 按钮在可排序中无法正常工作