linux 安裝gtest 單元測試

Before you start make sure your have read and understood this note from Google! This tutorial makes using gtest easy, but may introduce nasty bugs.

1. Get the googletest framework

$ wget https://github.com/google/googletest/archive/release-1.7.0.zip

Or get it by hand. I guess I won't manitain this little How-to, so if you stumbled upon it and the links are outdated, feel free to edit it.

2. Unzip and build google test

$ unzip gtest-1.7.0.zip
$ cd gtest-1.7.0
$ ./configure
$ make

3. "Install" the headers and libs on your system.

This step might differ from distro to distro, so make sure you copy the headers and libs in the correct directory. I accomplished this by checking where Debians former gtest libs were located. But I'm sure there are better ways to do this. Note: make install is dangerous and not supported

$ sudo cp -a include/gtest /usr/include
$ sudo cp -a lib/.libs/* /usr/lib/

4. Update the cache of the linker

... and check if the GNU Linker knows the libs

$ sudo ldconfig -v | grep gtest

If the output looks like this:

libgtest.so.0 -> libgtest.so.0.0.0
libgtest_main.so.0 -> libgtest_main.so.0.0.0

, everything is fine.

gTestframework is now ready to use. Just don't forget to link your project against the library by setting -lgtest as linker flag and optionally, if you did not write your own test mainroutine, the explicit -lgtest_main flag.

From here on you might want to go to Googles documentation about the framework to learn how it works. Happy coding!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章