测试驱动开发 2011-01-02

来源:互联网 发布:java websocket 书籍 编辑:程序博客网 时间:2024/05/13 15:46

GTest

 

1. 就篇介绍性文章

http://apps.hi.baidu.com/share/detail/24314152

 

CPPUnit / CXXTest

GTest

 

结论:GTest在多个方面明显胜出

 

2. GTest

官网:http://code.google.com/p/googletest/

 

3. first example: try.cpp

 

[root@localhost lab]# g++ -o try.cpp -c try.cpp
try.cpp:1:25: 错误:gtest/gtest.h:没有那个文件或目录
try.cpp:5: 错误:‘::testing’ 尚未声明
try.cpp:5: 错误:expected `{' before ‘Test’
try.cpp:5: 错误:无效的函数声明

[root@localhost lab]# g++ -o try.o -c try.cpp -I /study/gtest/gtest-1.5.0/include

 

[root@localhost lab]# libtool --mode=link gcc -g -O -o try try.o /study/gtest/gtest-1.5.0/lib/libgtest_main.la –lm
gcc -g -O -o .libs/try try.o –lm  /study/gtest/gtest-1.5.0/lib/.libs/libgtest_main.so /study/gtest/gtest-1.5.0/lib/.libs/libgtest.so  -Wl,--rpath -Wl,/usr/local/lib
gcc: –lm: No such file or directory
[root@localhost lab]#

 

 

[root@localhost gtest-1.5.0]# libtool --mode=link gcc -g -O -o try try.o /study/gtest/gtest-1.5.0/lib/libgtest_main.la
gcc -g -O -o .libs/try try.o  /study/gtest/gtest-1.5.0/lib/.libs/libgtest_main.so /study/gtest/gtest-1.5.0/lib/.libs/libgtest.so  -Wl,--rpath -Wl,/usr/local/lib
/study/gtest/gtest-1.5.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
/study/gtest/gtest-1.5.0/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
/study/gtest/gtest-1.5.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
/study/gtest/gtest-1.5.0/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status

Q: 似乎使用libtool比较复杂些


4. to make sample testing work! ->>> 仔细研究一下MakeFile !

 

  cd ${GTEST_DIR}/make
  make
  ./sample1_unittest

 

[root@localhost make]# ./sample1_unittest
Running main() from gtest_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN      ] FactorialTest.Negative
[       OK ] FactorialTest.Negative (0 ms)
[ RUN      ] FactorialTest.Zero
[       OK ] FactorialTest.Zero (0 ms)
[ RUN      ] FactorialTest.Positive
[       OK ] FactorialTest.Positive (0 ms)
[----------] 3 tests from FactorialTest (1 ms total)

[----------] 3 tests from IsPrimeTest
[ RUN      ] IsPrimeTest.Negative
[       OK ] IsPrimeTest.Negative (0 ms)
[ RUN      ] IsPrimeTest.Trivial
[       OK ] IsPrimeTest.Trivial (0 ms)
[ RUN      ] IsPrimeTest.Positive
[       OK ] IsPrimeTest.Positive (0 ms)
[----------] 3 tests from IsPrimeTest (0 ms total)

[----------] Global test environment tear-down
[==========] 6 tests from 2 test cases ran. (2 ms total)
[  PASSED  ] 6 tests.

 

 

5. others

* CMake:cross-platform-make

* 文件类型

.o,是目标文件,相当于windows中的.obj文件
.so 为共享库,是shared object,用于动态连接的,和dll差不多
.a为静态库,是好多个.o合在一起,用于静态连接
.la为libtool自动生成的一些共享库,vi编辑查看,主要记录了一些配置信息。可以用如下命令查看*.la文件的格式   $file *.la

 

 

原创粉丝点击