一,新建立一个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. ie被hao.360劫持的解决方法

    概述 之前无意中发现ie被hao.360劫持了,只要打开网址就会跳到hao.360,然后显示网络错误.网上试了几种解决方法,都不行,最后被我用重置ie浏览器的方法解决了.我总结了一下,把各种方案都记下 ...

  2. 在notepad++中使用正则匹配功能(一-龥!-~) 中文[利刃篇]

    用正则时间越久,人就越懒,就越知道正则的强大.正则,不只是在代码里用到,在字符查找是也会用到,学会适当使用正则,将会使你的工作事办功倍!但是,中文却是一个砍,不容易过. 于是在用notepad++,也 ...

  3. Autowired byType 与 byName 策略

    @Autowired是spring的注解,默认使用的是byType的方式向Bean里面注入相应的Bean.例如: @Autowiredprivate UserService userService;这 ...

  4. [Node.js与数据库]node-mysql 模块介绍

    [Node.js与数据库]node-mysql 模块介绍   转载至:https://itbilu.com/nodejs/npm/NyPG8LhlW.html#multiple-statement-q ...

  5. 京东架构师的showtime京东个性化推荐系统实战

    推荐系统核心任务是排序,从线上服务角度看,就是将数据从给定集合中数据选择出来,选出后根据一定规则策略方法进行排序. 线上服务要根据一定规则进行架构设计,架构设计是什么?每一次权衡取舍都是设计,设计需要 ...

  6. linux中变量的一些操作方法

    常见的一般有如下操作,可以对字符串进行简单操作: echo ${#var}打印变量var长度 echo "$var:3:8" 打印变量var第4个字符开始的8个字符echo ${v ...

  7. VMware12 安装 Ubuntu18.04

    安装Ubuntu18.04虚拟机 Ubuntu获取地址: 官网:https://www.ubuntu.com/download/server 清华镜像站:https://mirrors.tuna.ts ...

  8. 高手速成android开源项目【项目篇】

    主要介绍那些Android还不错的完整项目,目前包含的项目主要依据是项目有意思或项目分层规范比较好.Linux项目地址:https://github.com/torvalds/linuxAndroid ...

  9. mysql 查看建表语句

    show create table `table_name`; 结果如下:

  10. Java设计模式学习记录-桥接模式

    前言 这次介绍结构型设计模式中的第二种模式,桥接模式. 使用桥接模式的目的就是为了解耦,松散的耦合更利于扩展,但是会增加相应的代码量和设计难度. 桥接模式 桥接模式是为了将抽象化与实现化解耦,让二者可 ...