* Use gtest in
: Properties:
: Date: <on Monday>
: By: yafeilee
: End:
** Prepare the gtest framework
1.download gtest-1.6.0.zip
2. decompress the package and enter the gtest-1.6.0/msvc directory
3. Open the gtest project Compilation
4. Put the compiled gtest. lib and gtestd. Lib into the gtest-1.6.0/lib.
** Create a test project
1. Create a Win32 console application
2. Set the path of the gtest header file (addtional include directories)
3. Set the gtest. Lib path (additional dependencies)
4. Set the Runtime Library to/Mt or/MTD.
5. After gtest_main.lib is added, you do not need to write the _ tmain function.
6. Set "$ (targetdir) $ (targetfilename)" in the later generation event to automatically execute the unit test after generation.
** Test demo
# Include "stdafx. H"
# Include
Int add (int A, int B)
{
Return A + B;
}
Test (addtest, handlezeroinput)
{
Expect_eq (3, add (1, 2 ));
}
Int _ tmain (INT argc, _ tchar * argv [])
{
Testing: initgoogletest (& argc, argv );
Return run_all_tests ();
}