[QtCratot]_0_0_googletest单元测试

[QtCratot]_0_0_googletest单元测试

创建时间:20210822 16:36:00

获得googletest工程

  • 下载googletest工程到本地
    • git clone https://github.com/google/googletest.git

创建QT测试工程

  • 添加BaseUtil的测试工程
    在这里插入图片描述
    在这里插入图片描述

  • 选择googletest框架和cmake/qmake管理工程, 推荐qmake
    在这里插入图片描述

  • 执行验证
    在这里插入图片描述

编写测试用例,及运行后的测试结果

在这里插入图片描述

在这里插入图片描述

项目整理:GoogleTest可以只留下使用的文件

  • 删除没有用的示例和文档来减少文件管理

    googletest
    ├── googlemock
    │   ├── include
    │   └── src
    └── googletest
        ├── include
        └── src
    
    googletest
    ├── googlemock
    │   ├── include
    │   │   └── gmock
    │   │       ├── gmock-actions.h
    │   │       ├── gmock-cardinalities.h
    │   │       ├── gmock-function-mocker.h
    │   │       ├── gmock.h
    │   │       ├── gmock-matchers.h
    │   │       ├── gmock-more-actions.h
    │   │       ├── gmock-more-matchers.h
    │   │       ├── gmock-nice-strict.h
    │   │       ├── gmock-spec-builders.h
    │   │       └── internal
    │   │           ├── custom
    │   │           │   ├── gmock-generated-actions.h
    │   │           │   ├── gmock-matchers.h
    │   │           │   ├── gmock-port.h
    │   │           │   └── README.md
    │   │           ├── gmock-internal-utils.h
    │   │           ├── gmock-port.h
    │   │           └── gmock-pp.h
    │   └── src
    │       ├── gmock-all.cc
    │       ├── gmock-cardinalities.cc
    │       ├── gmock.cc
    │       ├── gmock-internal-utils.cc
    │       ├── gmock_main.cc
    │       ├── gmock-matchers.cc
    │       └── gmock-spec-builders.cc
    └── googletest
        ├── include
        │   └── gtest
        │       ├── gtest-death-test.h
        │       ├── gtest.h
        │       ├── gtest-matchers.h
        │       ├── gtest-message.h
        │       ├── gtest-param-test.h
        │       ├── gtest_pred_impl.h
        │       ├── gtest-printers.h
        │       ├── gtest_prod.h
        │       ├── gtest-spi.h
        │       ├── gtest-test-part.h
        │       ├── gtest-typed-test.h
        │       └── internal
        │           ├── custom
        │           │   ├── gtest.h
        │           │   ├── gtest-port.h
        │           │   ├── gtest-printers.h
        │           │   └── README.md
        │           ├── gtest-death-test-internal.h
        │           ├── gtest-filepath.h
        │           ├── gtest-internal.h
        │           ├── gtest-param-util.h
        │           ├── gtest-port-arch.h
        │           ├── gtest-port.h
        │           ├── gtest-string.h
        │           └── gtest-type-util.h
        └── src
            ├── gtest-all.cc
            ├── gtest.cc
            ├── gtest-death-test.cc
            ├── gtest-filepath.cc
            ├── gtest-internal-inl.h
            ├── gtest_main.cc
            ├── gtest-matchers.cc
            ├── gtest-port.cc
            ├── gtest-printers.cc
            ├── gtest-test-part.cc
            └── gtest-typed-test.cc
    
    12 directories, 57 files
    
  • 项目整理:将GoogleTest的配置文件,直接写到pro文件中

    # GoogleTest配置
    isEmpty(GOOGLETEST_DIR) {
        warning("Using googletest src dir specified at Qt Creator wizard")
        message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message")
        GOOGLETEST_DIR = ../googletest
    }
    
    !isEmpty(GOOGLETEST_DIR): {
        GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest
        GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock
    }
    
    requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR))
    
    !exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.")
    
    DEFINES += \
        GTEST_LANG_CXX11
    
    INCLUDEPATH *= \
        $$GTEST_SRCDIR \
        $$GTEST_SRCDIR/include \
        $$GMOCK_SRCDIR \
        $$GMOCK_SRCDIR/include
    
    SOURCES += \
        $$GTEST_SRCDIR/src/gtest-all.cc \
        $$GMOCK_SRCDIR/src/gmock-all.cc
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值