Googletest Framework Test C + + code
development Environment : Ubuntu16.04
- Determine if the installation
cmake
Input cmake -v
, if not installed, entersudo apt-get install cmake
Open Terminal input:git clone https://github.com/google/googletest.git
Create a folder to mydir
use as a directory for CMake.
mydir
under, enter the command: cmake $(TEST_DIR)
, ${GTEST_DIR}
for the downloaded GoogleTest
directory
Under the above mydir
, enter the make
command to install.
Build test.cpp
the file and test the code:
#include <gtest/gtest.h>#include <iostream>int test_fun(int a) { return1;}// 单元测试TEST(FunTest, HandlesZeroInput) { EXPECT_EQ(1, test_fun(0));}int main(intchar **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS();}
In the directory of the code, enter:
g++ test.cpp /usr/local/lib/libgtest.a -lpthread -o test
Which libgtest.a -lpthread
is the dynamic link library
Run later./test
Test success!
Finally spit the trough,,, this markdown editor is very simple ...
Googletest Framework Test C + + code