googletest入门

googletest:https://github.com/google/googletest 注tag1.12.1是支持C++11的
mkdir build;cd build
cmake -DCMAKE_C_COMPILER=arm-linux-gnueabihf-sigmastar-9.1.0-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-sigmastar-9.1.0-g++ …
make

lib目录下就是编译出来的静态库 libgmock.a libgmock_main.a libgtest.a libgtest_main.a
头文件路劲:…/googletest/include
如果链接了gtest_main,就不需要写main函数了,只要写TEST的测试用例(宏定义中不能有_)就好了,测试用例文件需要为cpp
参考链接:https://blog.csdn.net/weixin_39901032/article/details/127970251
gtest 支持一些参数输入设置:https://blog.csdn.net/King_weng/article/details/114289424,可以通过–help 查看
如: --gtest_repeat=-1 测试次数为无限, gtest_output=xml:./output.xml
–gtest_filter=testcase.json_post_get0 单例测试 TEST(testcase, json_post_get0)

TEST(para, json_www_get) para称为test suite, json_www_get称为test case,suite( 测试集合)可以包含多个case( 测试用例)
DISABLED:可以在测试集合或测试用例前面加,默认是不会跑的,用于一些已知会失败的,或者无限循环的例子
suite的setup方法:参考sample5_unittest,可以在suite开始前做相关的准备工作
定义class QuickTest : public testing::Test 以及TEST_F(QuickTest, json_www_get)

class ViscaTest : public testing::Test {
protected:
  void SetUp() override {
    //...setup work
  }
  void TearDown() override {
    //tear down work
  }
};

多线程测试:

void MyThreadFunction() {

}

TEST(MyMultiThreadTest, TestThreads) {
    const int num_threads = 2;
    address_init();
    // 创建多个线程,并启动它们
    std::vector<std::thread> threads;
    for (int i = 0; i < num_threads; i++) {
        threads.push_back(std::thread(MyThreadFunction));
    }


    // 等待每个线程完成
    for (auto& thread : threads) {
        thread.join();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值