当前位置:网站首页>Installation and use of GTEST and gmock
Installation and use of GTEST and gmock
2022-07-27 11:21:00 【lqw198421】
background
The project of the company adopts gtest For unit testing ( In fact, Huawei Hisilicon also used gtest, But the benefits of big factories ( Or it can also be said to be bad - dog head) Just don't care about these things ), Need to install gtest;
I was in docker Installed below , The steps should be the same ;
step
Source download
adopt git To download , Source code installation :
git clone https://github.com/google/googletest
compile
After downloading, a googletest Folder , After entering , adopt cmake To compile the , Enter the following 3 Command and execute :
cd googletest
cmake3 CMakeLists.txt
make
Be careful : According to personal cmake Set to , I installed cmake3, And no redirection , So it is cmake3
Header files and static library copies
My current version , In addition to downloading googletest Out of the folder , stay googletest There is another one in the catalog googletest , That is to say, the directory structure is : googletest/googletest – Use..., respectively googletest_1 and googletest_2 To specifically refer to 2 A directory file 
You can also see from the screenshot above , stay googletest_1 Except for googletest_2 Outside , One more googlemock, this 2 One is the goal :gtest and gmock
Static library copy
Static library generated after compilation :gtest(libgtest.a、libgtest_main.a) 、gmock(libgmock.a、libgmock_main.a); The directory is :
googletest_1 Under the lib Next :
Will these .a File copy to /usr/lib Under the table of contents :
cp ./lib/* /usr/lib Header file copy
The header file is in googletest_2 Under the include Catalog :
Need to put include Under the gtest Copy all directories to /usr/include Under the table of contents :
cp –a include/gtest /usr/include
alike , hold googletest_1 Under the googlemock In the directory include Under the gmock Copy it all to /usr/include Under the table of contents :
( You need to get into googletest_1 Of googlemock Under the table of contents )
cp –a include/gmock /usr/include
test
You can test through the following test code gtest Is the installation successful :
#include<gtest/gtest.h>
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();
}
Execute after compilation :
g++ test.cc -lgtest -lpthread
./a.out
Process and results :
边栏推荐
- I've compromised. Since everyone wants to call me Yelin, there's nothing I can do
- 记忆化搜索 AcWing 901. 滑雪
- Find the combination number acwing 888. find the combination number IV
- 博弈论 AcWing 893. 集合-Nim游戏
- SQL Server2000数据库错误
- Neural network learning notes
- 14 check whether integers and their multiples exist
- 博弈论 AcWing 894. 拆分-Nim游戏
- 栈 AcWing 3302. 表达式求值
- Cancer DDD
猜你喜欢

Longest ascending subsequence model acwing 272. longest common ascending subsequence

博弈论 AcWing 892. 台阶-Nim游戏

Inclusion exclusion principle acwing 890. divisible numbers

Longest ascending subsequence model acwing 1010. Interceptor missile

Game theory acwing 892. Step Nim game

Derive the detailed expansion of STO double center kinetic energy integral

最长上升子序列模型 AcWing 1016. 最大上升子序列和

Derivation of the detailed expansion sto overlap integrals

ethereum rpc

State compression DP acwing 91. shortest Hamilton path
随机推荐
Knapsack problem acwing 9. grouping knapsack problem
什么是私域流量?
容斥原理 AcWing 890. 能被整除的数
01 BTC cryptology principle
4 search insertion location
洛谷P1441 砝码称重
Backpack model acwing 1022. Collection of pet elves
Longest ascending subsequence model acwing 272. longest common ascending subsequence
背包模型 AcWing 1022. 宠物小精灵之收服
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
Learning notes - simple server implementation
JVM judges that the object is dead, and practices verify GC recycling
I've compromised. Since everyone wants to call me Yelin, there's nothing I can do
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
15 design movie rental system
Find the combination number acwing 885. find the combination number I
C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps
Maximized array sum after 13 K negations
Memory search acwing 901. Skiing
状态压缩DP AcWing 91. 最短Hamilton路径