GoogleTest:简单示例及ASSERT/EXPECT说明
使用GoogleTest其实并不难,以下是一个简单的实例:
$ tree
├── t1.hpp
└── t1_ut.cpp
1.t1.hpp被测试的程序:
template<class T>
T add(T a, T b)
{return a + b;
}template<class T>
T sub(T a, T b)
{return a - b;
}
2.t1_ut.cpp测试t1.hpp的测试程序
#include "t1.hpp"
#include "gtest/gtest.h"
#include <string>
#include <iostream>namespace {TEST(Add, Int){EXPECT_EQ(2, add(1, 1));}TEST(Add, String){std::string str1 = "Hello";std::string str2 = "World";std::cout << "begin string test 1"<< std::endl;