Open Resource Manager:Nautilus.
Get gtest
From:Https://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php
Get gtest-1.7.0-rc1.zip, download link, download the packaged source code
Or download it from the GIT Repository:Git clone https://github.com/google/googletest.git
Install gtest
Download gtest source package: gtest-1.7.0.zip
Unzip the package and go to the gtest-1.7.0 directory.
Cmake cmakelists.txt
After make, two static libraries are generated: libgtest. A libgtest_main.a.
Sudo CP libgtest *. A/usr/lib
Sudo CP-A include/gtest/usr/include
Test gtest
The following example shows how to compile the Official Use Cases in the sample directory.
CD sample
Compile case 1
G ++ sample1.cc sample1_unittest.cc-lgtest-lgtest_main-lpthread-O test1
Compile case 2
G ++ sample2.cc sample2_unittest.cc-lgtest-lgtest_main-lpthread-O Test2
The main function is not written in the sample1.cc and samplew.unittest.cc files.Libgtest_main.a
Library, as the program entry
Test your own use cases
Three source files
Source file of the first test function: simplemath. h
// Simplemath. h # include <cmath> double cubic (double D) {return POW (D, 3 );}
The second test case: testcase. cpp
# Include <gtest/gtest. h> # include "simplemath. H "test (footest, rightcase) {expect_eq (8, cubic (2);} test (footest, errcase) {expect_eq (27, cubic (3 ));}
Third entry: testmain. cpp
# Include <gtest/gtest. h> int main (INT argc, char * argv []) {testing: initgoogletest (& argc, argv); Return run_all_tests ();}
Makefile for compilation
Cc = g ++-STD = C ++ 11 prom = test deps = simplemath. h OBJ = testcase. O testmain. O libs =-lgtest-lpthread $ (PROM): $ (OBJ) $ (CC)-o $ (PROM) $ (OBJ) $ (libs) %. o: %. C $ (deps) $ (CC)-C $ <-O [email protected]
Getting started
Http://www.cnblogs.com/coderzh/archive/2009/03/31/1426758.html
Install and use gtest