您的位置:首页 > 运维架构 > Linux

linux 安装gtest 单元测试

2015-09-01 16:36 531 查看
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[/code] 
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!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: