Recently, a new project is developed to develop data models. There is a chance to start coding from scratch, and the opportunity will be followed by Google test practices that have never been followed.
The following is a record of feelings, which is also an accumulation.
I. Environment Construction
Version:
Download the latest version of googletest 1.60.
Use vs2010 for compilation.
Boost_1.49
Note: The previous 1.5 compilation in vs2010 has a problem.
Environment variable:
Gmock_dir = D: \ gmock-1.6.0
* Gtest_dir = D :\gmock-1.6.0 \ gtest
* Boost_root = D: \ boost_000049_0
Compile: Open D: \ gmock-1.6.0 \ msvc \ 2010 solution with vs2010. Compile and get gmock. Lib
Because googlemock already contains googletest, you only need googlemock here.
2. Establish a test project1: Create a Win32 console Program
Main program code
# Include "stdafx. H"
# Include <iostream>
# Include <gtest/gtest. h>
# Include <gmock/gmock. h>
Int _ tmain (INT argc, _ tchar * argv [])
{
Testing: initgooglemock (& argc, argv );
Int r = run_all_tests ();
Return 0;
}
2: Test Project Settings
/*************************************** **************************************** *
* Usage:
*
* 1:
* System variable path
* Gmock_dir = D: \ gmock-1.6.0
* Gtest_dir = D :\gmock-1.6.0 \ gtest
* Boost_root = D: \ boost_000049_0
* Betested_include = E: \ .. \ include
*
* 2:
* Settings
* C/C ++-> inlcude Directory: $ (gmock_dir)/include; $ (gtest_dir)/include; directory of the Class header file to be tested; directory of other header files
* Set other properties of the project:
* Configuration properties-General: output directory, intermediate directory, output execution file name
* Connector-General: additional library Directory:... \ Lib \ debug
* Input: add the dependency gmock. Lib.
*
* 3:
* Put gmock. Lib in the test project directory (and add it to the Project)
*
* 4:
* For file naming rules used for testing
* Use case files that use gmock for testing are prefixed with m
* Use case files that are tested using gtest with the T prefix
*
* 5:
* Create a mock file (mmock1.h, mmock1.cpp) and a test case (mcase1.h and mcase1.cpp) in the .. \ case directory ).
* Create the tested demo file class1.h/CPP in the .. \ src directory; func1.h/CPP
* Add these two directories to the Project Settings (C/C ++-> inlcude, see article 2nd)
*
** In the mock declaration file (mmock1.h) include class declaration file (mclass1.h)
* Include the mock declaration file (mmock1.h) in the test case file (mcase1.h)
*
* The mcase1.h file contains the gmock header file, namespace, and class and its mock Class header files.
*
* 6:
* The name of the test case package is the same as that of the tested class. For example, the name of the test case package and test case of point is test (point, create)
**************************************** **************************************** */
For example of code of the project to be continued, you can leave a message for request.