当前位置: 首页 > news >正文

Google单元测试sample分析(一)

本文开始从googletest提供的sample案例分析如何使用单元测试,

代码路径在googletest/googletest/samples/sample1.unittest.cc
本文件主要介绍EXPECT
*相关宏使用

EXPECT_EQ 判断是否相等
EXPECT_TRUE 是否为True
EXPECT_FALSE 是否为False

TEST(FactorialTest, Negative) {// This test is named "Negative", and belongs to the "FactorialTest"// test case.EXPECT_EQ(1, Factorial(-5));EXPECT_EQ(1, Factorial(-1));EXPECT_GT(Factorial(-10), 0);// <TechnicalDetails>//// EXPECT_EQ(expected, actual) is the same as////   EXPECT_TRUE((expected) == (actual))//// except that it will print both the expected value and the actual// value when the assertion fails.  This is very helpful for// debugging.  Therefore in this case EXPECT_EQ is preferred.//// On the other hand, EXPECT_TRUE accepts any Boolean expression,// and is thus more general.//// </TechnicalDetails>
}

下面介绍sample2_unittest.cc文件

这里测试MyString类,
EXPECT_STREQ(nullptr, s.c_string()); //这里的STREQ是判断字符串内容,s为空类比较要使用nullptr

TEST(MyString, DefaultConstructor) {const MyString s;// Asserts that s.c_string() returns NULL.//// <TechnicalDetails>//// If we write NULL instead of////   static_cast<const char *>(NULL)//// in this assertion, it will generate a warning on gcc 3.4.  The// reason is that EXPECT_EQ needs to know the types of its// arguments in order to print them when it fails.  Since NULL is// #defined as 0, the compiler will use the formatter function for// int to print it.  However, gcc thinks that NULL should be used as// a pointer, not an int, and therefore complains.//// The root of the problem is C++'s lack of distinction between the// integer number 0 and the null pointer constant.  Unfortunately,// we have to live with this fact.//// </TechnicalDetails>EXPECT_STREQ(nullptr, s.c_string());EXPECT_EQ(0u, s.Length());
}

相关文章:

  • elementUI 特定分辨率(如1920*1080)下el-row未超出一行却换行
  • Python深度学习实战-基于tensorflow原生代码搭建BP神经网络实现分类任务(附源码和实现效果)
  • Python:实现日历到excel文档
  • html5怎么实现语音搜索
  • SOLIDWORKS PDM 2024数据管理5大新功能
  • 制作自己的前端组件库并上传到npm上
  • 互动直播UI设置 之 主播UI
  • 【java学习—十】HashSet集合(4)
  • C++之左值、右值、std::forward、std::move总结(二百五十)
  • 禁用Google Chrome自动升级、查看Chrome版本号
  • pythonWeb主流框架分析
  • 服务器数据恢复—nas硬盘故障导致raid6失效、存储无法访问的数据恢复案例
  • 【vue】vue前端、生产(线上)环境请求unicloud云服务空间axios报错
  • 识别鼠标选中actor_vtkInteractorStyleTrackballActor
  • 竹云产品入选《2023年度上海市网络安全产业创新攻关成果目录》
  • 【391天】每日项目总结系列128(2018.03.03)
  • 【node学习】协程
  • egg(89)--egg之redis的发布和订阅
  • iOS 系统授权开发
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript 奇技淫巧
  • React Native移动开发实战-3-实现页面间的数据传递
  • SegmentFault 2015 Top Rank
  • vue数据传递--我有特殊的实现技巧
  • Yeoman_Bower_Grunt
  • 大快搜索数据爬虫技术实例安装教学篇
  • 大数据与云计算学习:数据分析(二)
  • 机器人定位导航技术 激光SLAM与视觉SLAM谁更胜一筹?
  • 利用jquery编写加法运算验证码
  • 面试遇到的一些题
  • 你不可错过的前端面试题(一)
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • !!【OpenCV学习】计算两幅图像的重叠区域
  • #每天一道面试题# 什么是MySQL的回表查询
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (1)虚拟机的安装与使用,linux系统安装
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (3)llvm ir转换过程
  • (C#)一个最简单的链表类
  • (k8s中)docker netty OOM问题记录
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (zt)最盛行的警世狂言(爆笑)
  • (八)Flask之app.route装饰器函数的参数
  • (超简单)使用vuepress搭建自己的博客并部署到github pages上
  • (附源码)spring boot校园健康监测管理系统 毕业设计 151047
  • (附源码)springboot人体健康检测微信小程序 毕业设计 012142
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (离散数学)逻辑连接词
  • (没学懂,待填坑)【动态规划】数位动态规划
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • .NET Core IdentityServer4实战-开篇介绍与规划
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .Net 访问电子邮箱-LumiSoft.Net,好用
  • .NET/C# 利用 Walterlv.WeakEvents 高性能地中转一个自定义的弱事件(可让任意 CLR 事件成为弱事件)
  • .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)