My settings
- Mac OS X 10.6.8(Snow Leopard)
- gcc 4.5.4
- cmake 2.8.5
Process
- Get source code of google test from svn repository
- Build googletest with cmake
- Create source file that has main function
- Create test code
- Build test code with g++
- Run the test
Place the source where you want.
svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn
Make a directory that cmake runs, which is good for anywhere. {GTEST_DIR} is where theres is googletest. It is success when you get libgtest.a and libgtest_main.a after build.
mkdir mybuild cd mybuild cmake ${GTEST_DIR} make
(3) Create source file that has main function
Create source file that has main function. You can find sample as below link.
You have to call below functions in main function.
- testing::InitGoogleTest(&argc, argv);
- RUN_ALL_TESTS();
#include <iostream> #include "gtest/gtest.h" GTEST_API_ int main(int argc, char **argv) { std::cout << "Running main() from testmain.cc\n"; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }(4) Craeate test code
#include "gtest/gtest.h" TEST(firstTest, abs) { EXPECT_EQ(1, abs( -1 )); EXPECT_EQ(1, abs( 1 )); }
You have to add the directory where there is googletest's header file into include path. You also have to build test code with static library of google test that you made at (2).
As below, testmain.cc is a file that has main function and mytest.cc is a file that has test code.
(6) Run the test
g++ -I{GTEST_DIR}/include testmain.cc mytest.cc libgtest.a libgtest_main.a -o mytes
(6) Run the test
No comments:
Post a Comment