windows下编译使用googletest
1. 编译
1.1 步骤
2.2 main.cpp
#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));
int main(int argc, char* argv[])
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
getchar();
return 0;
使用cmake生成vs工程后,便可运行上述例子
3. 扩展
也可使用源码形式把googletest引入到使用工程中,参考下面的链接:
https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project