参考: http://www.cnitblog.com/zouzheng/archive/2010/06/09/61614.html
gtest下载: http://googletest.googlecode.com/files/gtest-1.3.0.zip
已编译: /Files/mrfangzheng/gtest-include-lib.zip
- 下载解压打开msvc > gtest.sln编译, 我们需要
- gtest-1.3.0\msvc\Debug\gtestd.lib
- gtest-1.3.0\include
- 新建Win32 Console Application, 修改项目属性
C/C++
General > Addtional Include Directories > gtest-1.3.0\include
Code Generation > Runtime Library > Multi-threaded Debug (/MTd)
Linker
Addtional Dependencies > gtest-1.3.0\msvc\Debug\gtestd.lib - 测试文件如下
#include "stdafx.h"
#include <gtest/gtest.h>
int Foo(int a, int b)
{
if (a == 0 || b == 0)
{
throw "don't do that";
}
int c = a % b;
if (c == 0)
return b;
return Foo(b, c);
}
TEST(FooTest, HandleNoneZeroInput)
{
EXPECT_EQ(2, Foo(4, 10));
EXPECT_EQ(6, Foo(30, 18));
EXPECT_EQ(6, Foo(30, 182));
}
int _tmain(int argc, _TCHAR* argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}