首页 > 代码库 > 玩转Google开源C++单元测试框架Google Test系列(gtest)之一 初识gtest in Linux

玩转Google开源C++单元测试框架Google Test系列(gtest)之一 初识gtest in Linux

按照此文http://blog.csdn.net/calmreason/article/details/38488765下载源码包:gtest-1.3.0.zip,解压

进入文件夹执行:

./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

示例代码:

#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();

}

输出: