51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1472|回复: 0
打印 上一主题 下一主题

获取编译gtest

[复制链接]
  • TA的每日心情
    无聊
    昨天 09:32
  • 签到天数: 399 天

    连续签到: 5 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2018-12-26 16:27:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    获取并编译gtest

    gtest试图跨平台,理论上,它就应该提供多个版本的binary包。但事实上,gtest只提供源码和相应平台的编译方式,这是为什么呢?google的解释是,我们在编译出gtest时,有些独特的工程很可能希望在编译时加许多flag,把编译的过程下放给用户,可以让用户更灵活的处理。这个仁者见仁吧,反正也是免费的BSD权限

    源码的获取地址:http://code.google.com/p/googletest/downloads/list

    目前gtest提供的是1.6.0版本,我们看看与以往版本1.5.0的区别:

    1. Changes for 1.6.0:
    2. * New feature: ADD_FAILURE_AT() for reporting a test failure at the
    3. given source location -- useful for writing testing utilities.
    4. 。。。 。。。
    5. * Bug fixes and implementation clean-ups.
    6. * Potentially incompatible changes: disables the harmful 'make install'
    7. command in autotools
    复制代码
    就是最下面一行,make install禁用了,郁闷了吧?UNIX的习惯编译方法:./configure;make;make install失灵了,只能说google比较有种,又开始挑战用户习惯了。

    那么怎么编译呢?

    先进入gtest目录(解压gtest.zip包过程就不说了),执行以下两行命令:

    1. g++ -I./include -I./ -c ./src/gtest-all.cc
    2. ar -rv libgtest.a gtest-all.o
    复制代码
    之后,生成了libgtest.a,这个就是我们要的东东了。以后写自己的单元测试,就需要libgtest.a和gtest目录下的include目录,所以,这1文件1目录我们需要拷贝到自己的工程中。

    编译完成后怎么验证是否成功了呢?(相当不友好!)

    1. cd ${GTEST_DIR}/make
    2.   make
    3.   ./sample1_unittest
    复制代码

    如果看到:

    1. Running main() from gtest_main.cc
    2. [==========] Running 6 tests from 2 test cases.
    3. [----------] Global test environment set-up.
    4. [----------] 3 tests from FactorialTest
    5. [ RUN      ] FactorialTest.Negative
    6. [       OK ] FactorialTest.Negative (0 ms)
    7. [ RUN      ] FactorialTest.Zero
    8. [       OK ] FactorialTest.Zero (0 ms)
    9. [ RUN      ] FactorialTest.Positive
    10. [       OK ] FactorialTest.Positive (0 ms)
    11. [----------] 3 tests from FactorialTest (0 ms total)

    12. [----------] 3 tests from IsPrimeTest
    13. [ RUN      ] IsPrimeTest.Negative
    14. [       OK ] IsPrimeTest.Negative (0 ms)
    15. [ RUN      ] IsPrimeTest.Trivial
    16. [       OK ] IsPrimeTest.Trivial (0 ms)
    17. [ RUN      ] IsPrimeTest.Positive
    18. [       OK ] IsPrimeTest.Positive (0 ms)
    19. [----------] 3 tests from IsPrimeTest (0 ms total)

    20. [----------] Global test environment tear-down
    21. [==========] 6 tests from 2 test cases ran. (0 ms total)
    22. [  PASSED  ] 6 tests.
    复制代码

    那么证明编译成功了。


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-20 07:44 , Processed in 0.063058 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表