Eclipse C++,Cygwin 64,gcov,lcov 单体&覆盖率测试环境搭建笔记
1.下载并安装 Eclipse IDE for C/C++ Developers
https://eclipse.org/downloads/packages/eclipse-ide-cc-developers/lunasr1
2.下载并安装Cygwin
https://www.cygwin.com/
安装选择package的时候记得要选择gcc相关的所有
测试时使用到了boost,因此把boost相关的也装上
Devel下的包尽量都装一下。
3.下载并安装CDT gcov plugin
http://sourceforge.jp/projects/ginkgo/
→http://sourceforge.jp/projects/ginkgo/releases/32486
下载最新版,拷贝至Eclipse 的plugin目录下,重新启动Eclipse
4.部署并安装Google Test
https://code.google.com/p/googletest/
→https://code.google.com/p/googletest/downloads/list
下载最新版,然后参考以下的步骤
在合适的目录下将zip文件解压,在解压下的目录实行以下命令
(Cygwin环境)
> mkdir lib
> g++ -c -Iinclude -I. src/gtest-all.cc
> ar -rv lib/libgtest.a gtest-all.o
将解压目录下的[gtest-1.7.0/include]下的gtest目录拷贝到%CYGWIN64%/usr/include目录下
5.导入/新建工程
需要注意的是新建时的选项
Toolchain for Indexer Settings → Cygwin GCC
6.激活plugin
工程属性
Properties → C/C++ Builder → C Coverage → Activate nature[勾选]
Properties → C/C++ Builder → Setting → ToolSettings → Cygwin C Compiler → Miscellaneous → Other flags[追加-fprofile-arcs -ftest-coverage]
Properties → Setting → ToolSettings → Cygwin C Linker → Miscellaneous → Linker flags[追加-fprofile-arcs -ftest-coverage]
Properties → Setting → ToolSettings → Cygwin C Linker → Libraries → Libraries [gtest] Library[/cygdrive/c/cygwin64/lib]
*如果ToolSettings标签页没有显示,那么需要如下如下设定
Properties → C/C++ Builder → Builder Settings → Generate Makefiles automatically[勾选]
7.执行文件后,生成.gcda .gcno文件
执行
lcov -c -d . -o test.info
生成info文件
执行
genhtml ../test.info
生成报告html
8.LCOV关于生成branch分支
/etc/lcovrc和~/.lcovrc文件以下的配置有效
# Include branch coverage data display (can be disabled by the # --no-branch-coverage option of genhtml) genhtml_branch_coverage = 1 # Specify if branch coverage data should be collected and processed. lcov_branch_coverage = 1
google test测试不错的参考文档
http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html
参考用到的网站
http://www.nminoru.jp/~nminoru/diary/2013/09.html