Eclipse C++,Cygwin 64,gcov,lcov 單體&覆蓋率測試環境搭建筆記

1.下載並安裝 Eclipse IDE for C/C++ Developershtml

https://eclipse.org/downloads/packages/eclipse-ide-cc-developers/lunasr1eclipse

 

2.下載並安裝Cygwinide

https://www.cygwin.com/測試

安裝選擇package的時候記得要選擇gcc相關的全部網站

測試時使用到了boost,所以把boost相關的也裝上ui

Devel下的包儘可能都裝一下。google

 

3.下載並安裝CDT gcov plugincode

http://sourceforge.jp/projects/ginkgo/
→http://sourceforge.jp/projects/ginkgo/releases/32486htm

下載最新版,拷貝至Eclipse 的plugin目錄下,從新啓動Eclipseblog

 

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

相關文章
相關標籤/搜索