解读sample5
说明
被测试代码文件 | sample1.h、sample1.cc和sample3-inl.h |
测试代码文件 | sample5_unittest.cc |
官网上如是描述sample5:
Sample #5 is teaches how to reuse a test fixture in multiple test cases by deriving sub-fixtures from it.
sample5演示了如何通过继承的方式来复用fixture class的代码。
由于sample5_unittest.cc里面的class QueueTest,与之前sample中的代码存在命名冲突,所以我另外创建了一个叫做sample5的工程来跑sample5的代码。创建工程的步骤可参考我写的另外一篇文章《用Visual Studio创建集成了gtest的命令行工程》(链接:http://www.cnblogs.com/duxiuxing/p/4272343.html)。
理解被测试代码
sample5的被测试代码来自于前面的sample1和sample3,可以参考之前的文章:
- 《解读sample1》,链接:http://www.cnblogs.com/duxiuxing/p/4273228.html
- 《解读sample3》,链接:http://www.cnblogs.com/duxiuxing/p/4275646.html
理解测试代码
测试代码包含了以下两组test case:
第1组test case的代码是这么组织的:
test fixture/fixture class | IntegerFunctionTest : public QuickTest |
- test name 1 | Factorial:测试Factorial()函数 |
- test name 2 | IsPrime:测试IsPrime()函数 |
第2组test case的代码是这么组织的:
被测试的类 | class Queue |
test fixture/fixture class | QueueTest : public QuickTest |
- test name 1 | DefaultConstructor:测试默认构造函数 |
- test name 2 | Dequeue:测试Dequeue()函数 |
两组test case里面的fixture class都继承于同一个基类“class QuickTest”,这些类的继承关系如下图所示:
关于fixture class继承的建议
sample5的注释里面提出了一个非常不错的建议,可以把各种性能指标(比如执行时长,资源泄露)的检查代码放到基类去完成:
// This sample teaches how to reuse a test fixture in multiple test
// cases by deriving sub-fixtures from it.
//
// When you define a test fixture, you specify the name of the test
// case that will use this fixture. Therefore, a test fixture can
// be used by only one test case.
//
// Sometimes, more than one test cases may want to use the same or
// slightly different test fixtures. For example, you may want to
// make sure that all tests for a GUI library don't leak important
// system resources like fonts and brushes. In Google Test, you do
// this by putting the shared logic in a super (as in "super class")
// test fixture, and then have each test case use a fixture derived
// from this super fixture.
系列文章索引:http://www.cnblogs.com/duxiuxing/p/4270836.html
解读sample5的更多相关文章
- SDWebImage源码解读之SDWebImageDownloaderOperation
第七篇 前言 本篇文章主要讲解下载操作的相关知识,SDWebImageDownloaderOperation的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...
- SDWebImage源码解读 之 NSData+ImageContentType
第一篇 前言 从今天开始,我将开启一段源码解读的旅途了.在这里先暂时不透露具体解读的源码到底是哪些?因为也可能随着解读的进行会更改计划.但能够肯定的是,这一系列之中肯定会有Swift版本的代码. 说说 ...
- SDWebImage源码解读 之 UIImage+GIF
第二篇 前言 本篇是和GIF相关的一个UIImage的分类.主要提供了三个方法: + (UIImage *)sd_animatedGIFNamed:(NSString *)name ----- 根据名 ...
- SDWebImage源码解读 之 SDWebImageCompat
第三篇 前言 本篇主要解读SDWebImage的配置文件.正如compat的定义,该配置文件主要是兼容Apple的其他设备.也许我们真实的开发平台只有一个,但考虑各个平台的兼容性,对于框架有着很重要的 ...
- SDWebImage源码解读_之SDWebImageDecoder
第四篇 前言 首先,我们要弄明白一个问题? 为什么要对UIImage进行解码呢?难道不能直接使用吗? 其实不解码也是可以使用的,假如说我们通过imageNamed:来加载image,系统默认会在主线程 ...
- SDWebImage源码解读之SDWebImageCache(上)
第五篇 前言 本篇主要讲解图片缓存类的知识,虽然只涉及了图片方面的缓存的设计,但思想同样适用于别的方面的设计.在架构上来说,缓存算是存储设计的一部分.我们把各种不同的存储内容按照功能进行切割后,图片缓 ...
- SDWebImage源码解读之SDWebImageCache(下)
第六篇 前言 我们在SDWebImageCache(上)中了解了这个缓存类大概的功能是什么?那么接下来就要看看这些功能是如何实现的? 再次强调,不管是图片的缓存还是其他各种不同形式的缓存,在原理上都极 ...
- AFNetworking 3.0 源码解读 总结(干货)(下)
承接上一篇AFNetworking 3.0 源码解读 总结(干货)(上) 21.网络服务类型NSURLRequestNetworkServiceType 示例代码: typedef NS_ENUM(N ...
- AFNetworking 3.0 源码解读 总结(干货)(上)
养成记笔记的习惯,对于一个软件工程师来说,我觉得很重要.记得在知乎上看到过一个问题,说是人类最大的缺点是什么?我个人觉得记忆算是一个缺点.它就像时间一样,会自己消散. 前言 终于写完了 AFNetwo ...
随机推荐
- 【开源java游戏框架libgdx专题】-01-libgdx介绍
libgdx是一款开源的java游戏框架,而且还实现了Desktop/Android/BlackBerry/iOS/HTML5这些些平台的跨平台开发.官方网址:https://libgdx.badlo ...
- jquery/js当前URL对当前栏目高亮突出显示
html: 1 <div class="nav"> 2 <ul> 3 <li><a href="index.html" ...
- Linq101-Aggregate
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Aggrega ...
- 安装ZendDebugger 调试php
一直懒得装断点调试工具,平时调试就用echo var_dump debug_print_backtrace 搞搞. 今天同事装了个xdebug,看着眼馋.于是想自己也装一个,由于平时用zend stu ...
- this,super关键字的使用
this关键字 1.this是对象的别名,是当前类的实例引用 2.在类的成员方法内部使用,代替当前类的实例.在Java中,本质上是指针,相当于C++中的指针概念.如果方法中的成员在调用前没有操作实例名 ...
- 【转】 UITableView 的indexPath
原文:http://blog.csdn.net/mengtnt/article/details/6733691 前面说过了viewController的一些基本注意事项.这里针对不同的viewCont ...
- C盘不能新建文件的问题解决办法
C盘不能新建文件的问题解决办法 主要症状: 1.C 盘文件不能修改2.C 盘不能新建文件3.总之就是只能读取不能,写入和修改这样对于平时操作造成了极其的不方便~~~复制文件到C 盘会提示:错误0×80 ...
- android布局1
第二类:属性值必须为id的引用名“@id/id-name” 仅RelativeLayout中有效 android:layout_below 在某元素的下方 android:la ...
- 下拉列表框 select 动态赋值
<tr> <td class="label">所属群组:</td> <td> <select name="group ...
- 【leetcode】1. Two Sums
题目 https://leetcode.com/problems/two-sum/ Given an array of integers, find two numbers such that t ...