使用VS2005建立最精简Google C++ Test项目示例(教程)

工程代码下载

详细步骤如下:

1,编译生成gtest.lib和gtestd.lib静态库,分别对应Release和Debug版本. (附件中有)

2,在VS2005的工程属性中包含gtest的include和lib目录. (附件中有)

3,使用VS2005建立空项目,工程属性的设置:
 
rel="File-List" href="file:///D:%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">

工程属性设置

Release

Debug

C/C++->代码生成->运行时库

多线程(/MT)

线调试(/MTd)

C/C++->代码生成->基本运行时检查

默认值

两者(/RTC1,等同于 /RTCsu)

链接器->输入->附加依赖项

Gtest.lib

Gtestd.lib



4,输入MyMath.h和MyMath.cpp源文件如下:
MyMath.h:
  1. class MyMath
  2. {
  3. public:
  4.     static int Add(int num1, int num2);
  5. };


MyMath.cpp:
  1. #include "MyMath.h"
  2. int MyMath::Add(int num1, int num2)
  3. {
  4.     return num1 + num2;
  5. }


5,建立测试文件MyMathTest.cpp如下:
  1. #include "MyMath.h"
  2. #include <gtest/gtest.h>
  3. TEST(MyMathTest, Positive)
  4. {
  5.     EXPECT_EQ(3, MyMath::Add(1, 2));
  6. }


6,建立主执行文件main.cpp如下:
  1. #include <iostream>
  2. #include <gtest/gtest.h>
  3. int main(int argc, char **argv) {
  4.     std::cout << "Running main() from gtest_main.cc/n";
  5.     testing::InitGoogleTest(&argc, argv);
  6.     return RUN_ALL_TESTS();
  7. }


7,编译执行即可,输出如下:
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值