GTest安装使用

本文介绍了GoogleTest,一个由Google开发的满足特定需求的测试框架,适用于各种平台的C++代码编写。文章详细讲解了如何安装、使用以及示例测试代码。
摘要由CSDN通过智能技术生成

googletest helps you write better C++ tests.

googletest is a testing framework developed by the Testing Technology team with Google's specific requirements and constraints in mind. No matter whether you work on Linux, Windows, or a Mac, if you write C++ code, googletest can help you. And it supports any kind of tests, not just unit tests.

1. 安装GTest

git clone https://github.com/google/googletest.git

cd googletest

mkdir build

cd build

cmake ..

make

sudo make install

2. 使用GTest

#include <gtest/gtest.h>

int Foo(int a,int b) {

    if(0 == a||0 == b) {

        throw "don't do that";

    }

    int c = a % b;

    if (0 == c) {

        return b;

    }

    return Foo(b, c);

}

TEST(FooTest, HandleNoneZeroInput) {

   EXPECT_EQ(2, Foo(4,10));

   EXPECT_EQ(6, Foo(30,18));

}

int main(int argc,char*argv[]) {

   testing::InitGoogleTest(&argc,argv);

   return RUN_ALL_TESTS();

}

g++ -std=c++11 deepinout.com.cpp -lgtest -lpthread

./a.out

4. 参考文档

GoogleTest User’s Guide | GoogleTest

gtest使用指南-Google版.docx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值