- Download project https://github.com/google/googletest
- The project file into the specified location
- unzip unzip the project file
- cmake ./
- make compilation
- Then include files in the project folder, lib folder into the current directory
- Main.cpp file a written test, unit.h + unit.c achieve a certain function, function declarations in header files, .c in implementation.
#ifndef _UNIT_H
#define _UNIT_H
int add(int a, int b);
#endif
#include<stdio.h>
#include"unit.h"
int add(int a, int b){
return a + b;
}
- In Test main (with specific reference to the source)
#include"unit.h"
#include<gtest/gtest.h>
#include<iostream>
using namespace std;
TEST(test, add_function){
EXPECT_EQ(add(3, 4), 7);
}
int main(int argc, char *argv[]){
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
- In the Link + compiler, the ultimate command g ++ --std = c ++ 11 -I./include -L./lib main.cpp unit.c -lgtest -lpthread achieve compilation phase
- Finally ./a.out output