Install and use gtest

Source: Internet
Author: User

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.aLibrary, 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.