Operating System: fedora15-x86_64
1. Download and decompress the package to/home/HLF,
Music gtest-1.60 gtest
CD gtest
2, G ++-I./include-I./-C./src/gtest-all.cc (note,-I after no space, directly Add ./)
3. ar-RV libgtest. A gtest-all.o
Note:
Although there are configure in the directory or makefile files in the make directory, they are all blind.
Simple test:
Let's test a max function in Foo. H (calculate a larger one of the two numbers)
The Foo. h file is as follows:
# Ifndef _ foo_h __# DEFINE _ foo_h _ intmax (INTA, intb) {returna> B? A: B;} # endif
Write the test program foo_test.cpp to test FOO:
The foo_test.cpp file is as follows:
# Include "gtest/gtest. H "# include" foo. H "test (Foo, max) {expect_eq (2, max (2,-1); expect_eq (3, max (2, 3);} intmain (intargc, char ** argv) {: Testing: initgoogletest (& argc, argv); returnrun_all_tests ();}
Compile foo_test.cpp with the following command:
G ++-G foo_test.cpp-O foo_test-I/home/HLF/gtest/include-L/home/HLF/-lgtest-lpthread
Note that you need to link the pthread library.
Test results:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from foo
[Run] Foo. Max
[OK] Foo. Max (0 MS)
[----------] 1 test From Foo (1 MS total)
[----------] Global test environment tear-down
[===========] 1 test from 1 test case ran. (3 MS total)
[Passed] 1 test.