GoogleTest 小结

1. GoogleTest 安装, 基于gtest V1.10

git clone https://github.com/google/googletest
cd googletest
cmake CMakeLists.txt
make
sudo cp lib/lib*.a  /usr/lib
sudo cp –a googletest/include/gtest /usr/include
sudo cp –a googlemock/include/gmock /usr/include

2. 用法小结

2.1 简单测试安装
#include
int add(int a,int b){
    return a+b;
}
TEST(testCase,test0){
    EXPECT_EQ(add(2,3),5);
}
int main(int argc,char **argv){
  testing::InitGoogleTest(&argc,argv);
  return RUN_ALL_TESTS();
}
2.2 系统测试
#include 
#include 

using namespace std;

class Student {
public:
  Student() : age_(0){}
  Student(int a): age_(a){}

  void print() {
    cout << "*******"<

输出结果

[==========] Running 2 tests from 1 test suite.
[----------] Global test environment set-up.
Foo FooEnvironment SetUp
[----------] 2 tests from TestMap
Call TestMap SetUpTestSuite.
[ RUN      ] TestMap.Test1
Call TestMap SetUp functions.
Test1 starts
*******0*********
Call TestMap TearDown functions.
[       OK ] TestMap.Test1 (0 ms)
[ RUN      ] TestMap.Test2
Call TestMap SetUp functions.
Test2 starts
*******0*********
Call TestMap TearDown functions.
[       OK ] TestMap.Test2 (0 ms)
Call TestMap TearDownTestSuite.
[----------] 2 tests from TestMap (0 ms total)

[----------] Global test environment tear-down
Foo FooEnviroment TearDown
[==========] 2 tests from 1 test suite ran. (1 ms total)
[  PASSED  ] 2 tests.

你可能感兴趣的:(GoogleTest 小结)