Google C + + unit Testing Framework

Source: Internet
Author: User

I. Overview

The Google C + + unit Testing Framework (GTEST), which can be used on multiple platforms (including Linux, Mac OS X, Windows, Cygwin, and Symbian), provides rich assertions, fatal and nonfatal failure judgments, value parameterization testing, Type parameterization test, "Death test". Gtest is an open source project, its source can be downloaded from here, the current code release is 1.6.0.

Compile

The Readme file in the source package explains how to compile the Gtest source code, directory msvc, Xcode contains the windows, Mac OS x platform related project files, CMake directory is used cmake for makefiles and project generation of related files, If you are under Unix/linux, execute the make command directly in the source directory to edit

You do not need to execute the make install command to install Gtest-related header files and library files when compiling your own test code, referencing the header and library files from the current directory.

Second, the implementation of use cases

Source file samples directory for us to provide a number of use cases, from Sample1 to sample9,gtest the author of the way to explain the use of gtest, how to execute these use cases?

First enter the directory of the Make directory, which contains a makefile file, execute make command, you can see after the made command to add several files in the directory, where Sample1_unittest is the sample1 executable file. Execute./sample1_unittest to see the results of the test run:

To compile an executable file that generates other use cases, we can refer to the makefile file under the Make directory, or perform the following steps:

Copy the Gtest-main.a dynamic library file to the Samples directory and execute the following command:

$ g++-I.. /include/-C sample2_unittest.cc  

And:

$ g++-I.. /INCLUDE/SAMPLE2.O SAMPLE2_UNITTEST.O Gtest_main.a-lpthread-o Test2

Finally we get sample2 executable file Test2, after these steps, I believe you also know how to generate their own gtest test execution files.

Method Two:

Modify the makefile file in the Make directory, change the sample1 to the target sample, and do

Google C + + unit Testing Framework

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.