进入文件夹执行:
./configure
make
make install
完毕即可正常使用:
(1)包含include目录 -I/root/scp/gtest/gtest-1.3.0;
(2)包含lib中的动态链接库:-lgtest -L/root/scp/gtest/gtest-1.3.0/lib
示例代码:
[cpp] view plaincopy
- #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 ACE_TMAIN(int argc, ACE_TCHAR* argv[])
- {
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
- }
输出:
玩转Google开源C++单元测试框架Google Test系列(gtest)之一 初识gtest,布布扣,bubuko.com
时间: 2024-10-24 00:23:27