XCode使用googletest(包括googlemock)

1. 下载最新的googletest源代码,也可以从此处下载:https://pan.baidu.com/s/1qRn5BCpUIBz_PY0m6-7pgg

2. 解压后进入googletest/make,执行make,copy libgtest.a到/usr/local/lib,并copy include/gtest目录到/usr/local/include;

然后进入googlemock/make,执行make,copy gmock_main.a到/usr/local/lib

3.新建一个空白的c++项目,并将main.cpp里面的内容清空

4.添加路径到项目,如下图:

5.添加.a文件到项目,如下图

6.添加如下代码到main.cpp,直接执行:

//
//  main.cpp
//  gtestdemo
//
//  Created by dotphoenix@qq.com on 23/07/2018.
//  Copyright © 2018 bifang. All rights reserved.
//

int HighestCommonDivissor(int a, int b)
{
	if (a == 0 || b == 0)
	{
		throw "don't do that";
	}
	int c = a % b;
	if (c == 0)
		return b;
	return HighestCommonDivissor(b, c);
}

#include <gtest/gtest.h>

TEST(HighestCommonDivissorTest, HandleNoneZeroInput)
{
	EXPECT_EQ(2, HighestCommonDivissor(4, 10));
	EXPECT_EQ(6, HighestCommonDivissor(30, 18));
}

7.得到如下结果:

Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from FooTest
[ RUN      ] FooTest.HandleNoneZeroInput
[       OK ] FooTest.HandleNoneZeroInput (0 ms)
[----------] 1 test from FooTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (1 ms total)
[  PASSED  ] 1 test.

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值