codeblocks+Mingw 下配置开源c++单元测试工具 google test
2013-11-07 16:25
513 查看
google test 是google的c++开源单元测试工具,chrome的开发团队就是使用它。
Code::Blocks 12.11(MinGW 4.7.1) (Windows版)
Google Test 1.7.0
一 编译Google Test
运行cmake-gui
在弹出来的对话框中
Where is the source code之后填写解压的gtest,例如:D:/software/gtest-1.7.0
Where to build the binaries之后填写生成的工程路径,例如:D:/software/gtest-1.7.0/codeblocks-mingw
(网上看到说要点击Configure,然后勾选gtest_disable_pthreads之后的复选框,再进行下面的操作,这一步我没有做也没问题)
点击Configure
然后点击Generate
如此一来,cmake就在D:/software/gtest-1.7.0/codeblocks-mingw下会自动生成Code::Blocks的project文件。
双击该project文件(cbp文件),然后build就行了。
二 使用Google Test
需要注意的是:
既想用C++11的新特征,又想顺利编译Google Test,你得用命令行参数-std=gnu++11,而不是-std=c++11。
用codeblocks新建一个工程
右键project,选择Build options...
清除Compiler settings > Compile Flags下与-std=有关的复选框
点击选项卡Compiler settings > Other options,在对话框中填写-std=gnu++11
(如果没有使用c++11新特性,上面两步可以省略)
在Linker settings > Other linker options下填写-lgtest
点击OK
点击选项卡Search directories
在Compiler子选项卡中Add一项,填写D:/software/gtest-1.7.0\include
在Linker子选项卡中Add一项,填写D:/software/gtest-1.7.0\codeblocks-mingw
点击OK
然后就可以写代码了,我写了一个add函数,然后对其测试,代码如下:
结果如图:
详细的使用说明请参考:here
【版权声明】转载请注明出处:/article/4879627.html
Code::Blocks 12.11(MinGW 4.7.1) (Windows版)
Google Test 1.7.0
一 编译Google Test
运行cmake-gui
在弹出来的对话框中
Where is the source code之后填写解压的gtest,例如:D:/software/gtest-1.7.0
Where to build the binaries之后填写生成的工程路径,例如:D:/software/gtest-1.7.0/codeblocks-mingw
(网上看到说要点击Configure,然后勾选gtest_disable_pthreads之后的复选框,再进行下面的操作,这一步我没有做也没问题)
点击Configure
然后点击Generate
如此一来,cmake就在D:/software/gtest-1.7.0/codeblocks-mingw下会自动生成Code::Blocks的project文件。
双击该project文件(cbp文件),然后build就行了。
二 使用Google Test
需要注意的是:
既想用C++11的新特征,又想顺利编译Google Test,你得用命令行参数-std=gnu++11,而不是-std=c++11。
用codeblocks新建一个工程
右键project,选择Build options...
清除Compiler settings > Compile Flags下与-std=有关的复选框
点击选项卡Compiler settings > Other options,在对话框中填写-std=gnu++11
(如果没有使用c++11新特性,上面两步可以省略)
在Linker settings > Other linker options下填写-lgtest
点击OK
点击选项卡Search directories
在Compiler子选项卡中Add一项,填写D:/software/gtest-1.7.0\include
在Linker子选项卡中Add一项,填写D:/software/gtest-1.7.0\codeblocks-mingw
点击OK
然后就可以写代码了,我写了一个add函数,然后对其测试,代码如下:
#include<cstdio> #include<gtest/gtest.h> int add(int a, int b) { return a+b; } TEST(addtest, HandleNoneZeroInput) { EXPECT_EQ(14, add(4, 10)); EXPECT_EQ(-2, add(-3, 1)); } int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); return 0; }
结果如图:
详细的使用说明请参考:here
【版权声明】转载请注明出处:/article/4879627.html
相关文章推荐
- codeblocks+Mingw 下配置开源c++单元测试工具 google test
- 玩转Google开源C++单元测试框架Google Test系列(gtest)
- 单元测试工具googletest C++Test和CppUnit
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之五 - 死亡测试
- Google开源C++单元测试框架Google Test(gtest)在C++Builder(xe5)下的使用-1
- 开源C++单元测试框架Google Test的简单使用
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之三 - 事件机制
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之五 - 死亡测试
- 玩转Google开源C++单元测试框架Google Test系列(gtest)
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之一 - 初识gtest
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之二 - 断言
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之一 - 初识gtest
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之七 - 深入解析gtest
- 玩转Google开源C++单元测试框架Google Test系列
- (转)玩转Google开源C++单元测试框架Google Test系列(gtest)之八 - 打造自己的单元测试框架
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之六 - 运行参数
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之六 - 运行参数
- 玩转Google开源C++单元测试框架Google Test系列(gtest)(总)
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之一 - 初识gtest
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之六 - 运行参数