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