一,新建立一个hello工程---》在左侧会看到helloTests---->helloTests.m.如下图所示。

二,打开查看会看到如下代码。

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h> @interface helloTests : XCTestCase @end @implementation helloTests - (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
} - (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
} - (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
} - (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
} @end

三,里面函数的说明。

1. -(void)setUp: 每个test方法执行前调用,用于类的创建,一些变量的初始化等

2. -(void)tearDown:每个test方法执行后调用

3. -(void)testXXX:这个是真正运行的测试方法,命名就是不带参数,以test开始。

四,Product-->Test--》运行测试。输出结果如下图所示:

Test Suite 'All tests' started at 2016-01-23 05:08:13 +0000
Test Suite 'helloTests.xctest' started at 2016-01-23 05:08:13 +0000
Test Suite 'helloTests' started at 2016-01-23 05:08:13 +0000
Test Case '-[helloTests testExample]' started.
Test Case '-[helloTests testExample]' passed (0.000 seconds).
Test Case '-[helloTests testPerformanceExample]' started.
/Users/chenlihua/Desktop/hello/helloTests/helloTests.m:35: Test Case '-[helloTests testPerformanceExample]' measured [Time, seconds] average: 0.000, relative standard deviation: 121.431%, values: [0.000002, 0.000001, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000], performanceMetricID:com.apple.XCTPerformanceMetric_WallClockTime, baselineName: "", baselineAverage: , maxPercentRegression: 10.000%, maxPercentRelativeStandardDeviation: 10.000%, maxRegression: 0.100, maxStandardDeviation: 0.100
Test Case '-[helloTests testPerformanceExample]' passed (0.288 seconds).
Test Suite 'helloTests' passed at 2016-01-23 05:08:13 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.288 (0.289) seconds
Test Suite 'helloTests.xctest' passed at 2016-01-23 05:08:13 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.288 (0.290) seconds
Test Suite 'All tests' passed at 2016-01-23 05:08:13 +0000.
Executed 2 tests, with 0 failures (0 unexpected) in 0.288 (0.291) seconds

参考资料:《iOS测试指南》

【读书笔记】iOS-OCUnit-单元测试的更多相关文章

  1. [读书笔记]iOS 7 UI设计 对比度

    好久没写随笔了,最近在读<iOS 7 byTutorials>,很不错,推荐给大家. 每一个好的程序员也都是一个设计师,不懂设计的程序员不是好的CTO.哈哈,开个小玩笑. iOS 7设计的 ...

  2. 读书笔记-iOS核心动画高级技巧

    如果不使用+imageNamed:,那么把整张图片绘制到CGContext可能是最佳的方式了. 这里我们利用了CALayer的KVC来存储和检索任意的值,将图层和索引打标签. 使用KVC打标签

  3. 读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit

    读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit Author: Andrew Hunt ,David Thomas with Matt ...

  4. <读书笔记> 代码整洁之道

    概述      1.本文档的内容主要来源于书籍<代码整洁之道>作者Robert C.Martin,属于读书笔记. 2.软件质量,不仅依赖于架构和项目管理,而且与代码质量紧密相关,本书提出一 ...

  5. <读书笔记>软件调试之道 :问题的核心-修复后的反思

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! ---------------------------------------- ...

  6. <读书笔记>软件调试之道 :问题的核心-如何修复缺陷

    声明:本文档的内容主要来源于书籍<软件调试修炼之道>作者Paul Butcher,属于读书笔记.欢迎转载! 修复缺陷 对于一个好的修复来说,不仅仅是让软件运行正确,还需要为将来奠定基础.一 ...

  7. 远程办公《Remote》读书笔记:中国程序员在家上班月入过六万不是梦

    这不是一本新书,这是一本很值得中国程序员看的老书,所以我不是来做卖新书广告的:) 但它的确是一本好书,这本书在Amazon上3个business categories排第一.作者Jason Fried ...

  8. HTML5&CSS3读书笔记

    Hi All, 分享一下我学HTML5 摘抄的读书笔记(我用的还是英文,因为一些新的东西还是来自于欧美国家,希望大家习惯于看一些英文材料): 1. Difference between Section ...

  9. 可靠的、可扩展的、可维护的数据系统 ------《Designing Data-Intensive Applications》读书笔记1

    坦白说也是机缘巧合,在硕士生阶段进入分布式系统领域学习.无论是大规模存储或计算,其核心也是运用分布式技术利用并行性来解决数据密集型应用的需求.最近开始在啃这本<Designing Data-In ...

  10. 读书笔记--Android Gradle权威指南(下)

    前言 最近看了一本书<Android Gradle 权威指南>,收获挺多,就想着来记录一些读书笔记,方便后续查阅. 本篇内容是基于上一篇:读书笔记--Android Gradle权威指南( ...

随机推荐

  1. linux下报错bash: service: command not found

    在linux下操作的时候经常会遇到,bash: service: command not found这个错误,以前在网上找了,照着弄了,也没细看原因,今天又碰到这个问题,就顺便研究一下. 1.通常这种 ...

  2. Maven 的安装与配置

    最近公司需要新起一个项目,想使用maven+springmvc+spring+mybatis+mysql实现,以前我们的项目都是传统的老项目,没用过maven,Eclipse版本是GALILEO的,有 ...

  3. struts2框架学习笔记7:struts2标签

    三大标签: 1.JSP:脚本,为了替代servlet,已过时 2.JSTL:标准标签库(core.format.sql.xml),还未淘汰的只有core库 3.Struts2标签库:由Struts2开 ...

  4. LabVIEW(十一):条件结构的巧用

    一.LabVIEW中条件结构使用起来并不是那么简便,主要体现在两点: 1.由隧道的产生引起的一些问题.(当箭头停留在隧道处时不显示为“自动索引隧道”,所以此隧道非彼隧道) 2.由多层结构判断引起的不易 ...

  5. SQL-2--TRIGGER

    触发器TRIGGER 是一个被指定关联到一个表的数据库对象,当对一个表的特定事件出现时,它将被激活. 触发器是数据库响应 INSERT , UPDATE, DELITE 语句而自动执行的一条SQL语句 ...

  6. Rip配置

    Rip配置 首先建立如图拓扑图 分别配置两台电脑的ip地址和子网掩码和网关.如图所示. 在router0上配置两个端口的IP以及子网掩码 在路由器router0上配置rip2协议.里面的no auto ...

  7. Build step 'Execute shell' marked build as failure解决

    今天jenkins构建时运行脚本报错如下: Build step 'Execute shell' marked build as failure 脚本没问题后来看了下原因是磁盘空间不足导致报错,清除下 ...

  8. Python必会的单元测试框架 —— unittest

    用Python搭建自动化测试框架,我们需要组织用例以及测试执行,这里博主推荐Python的标准库——unittest. unittest是xUnit系列框架中的一员,如果你了解xUnit的其他成员,那 ...

  9. Xcode 8.X Command Line Tools

    Summary Step 1. Upgrade Your System to macOS Sierra Step 2. Open the Terminal Application Step 3. Is ...

  10. Django集成Markdown编辑器【附源码】

    专注内容写作的你一定不要错过markdown 简单介绍 markdown是一种标记语言,通过简单的标记语法可以使普通的文本内容具有一定的格式,使用非常简单,学习成本极低 目前各大Blog平台都已支持m ...