当前位置:网站首页>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 :
边栏推荐
- Luogu p1441 weight weighing
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- 14 check whether integers and their multiples exist
- Wechat push - template message parameter configuration
- Learning notes uni app
- Shortest moving distance and entropy of morphological complex
- 数字三角形模型 AcWing 1018. 最低通行费
- The difference of iteration number and information entropy
- 11 wrong set
- Tensorflow tensor operation function set
猜你喜欢

Find the combinatorial number acwing 889. 01 sequence satisfying the condition

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft

Chinese remainder theorem acwing 204. strange way of expressing integers

最长上升子序列模型 AcWing 272. 最长公共上升子序列

背包模型 AcWing 423. 采药

背包模型 AcWing 1024. 装箱问题

Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?

Cancer DDD

Influence of black and white pixel distribution on iteration times

Knapsack problem acwing 9. grouping knapsack problem
随机推荐
2022牛客多校 (3)J.Journey
What is the mystery of the gate of the meta universe?
Tree data conversion
Luogu p1441 weight weighing
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
Miscellaneous records of Finance
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
最长上升子序列模型 AcWing 1016. 最大上升子序列和
洛谷P1441 砝码称重
背包问题 AcWing 9. 分组背包问题
求组合数 AcWing 887. 求组合数 III
Game theory acwing 893. Set Nim game
深析C语言的灵魂 -- 指针
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
什么是私域流量?
Local and overall differences between emergence and morphology
Learning notes - simple server implementation
Opengauss kernel analysis - statistics and row count estimation
Derive the detailed expansion of STO double center kinetic energy integral
JVM judges that the object is dead, and practices verify GC recycling