一,新建立一个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. Thinking in Java from Chapter 21

    From Thinking in Java 4th Edition 并发 线程可以驱动任务,因此你需要一种描述任务的方式,这可由Runnable接口来提供. 要想定义任务,只需要实现Runnable接 ...

  2. WebRTC 学习之 Intel® Collaboration Suite for WebRTC 关键类整理

    关键类整理 ---> ConferenceClient.ConferenceClientObserver. 一.ConferenceClient ConferenceClient是一个应用程序在 ...

  3. MySQL slow_log表不能修改成innodb引擎

    背景 从mysql.slow_log 获取慢查询日志很慢,该表是csv表,没有索引. 想添加索引来加速访问,而csv引擎不能添加索引(csv引擎存储是以逗号分割的文本来存储的),只能改存储引擎来添加索 ...

  4. js中数字直接点方法会报错,如1.toString()

    Number(11).toString() "11" var num = 111; undefined num.toString() "111" .toStri ...

  5. django 中文入门文档

    django中文入门文档:阅读地址

  6. 课程四(Convolutional Neural Networks),第二 周(Deep convolutional models: case studies) —— 0.Learning Goals

    Learning Goals Understand multiple foundational papers of convolutional neural networks Analyze the ...

  7. go 通过http发送图片file内容

    package main import ( "encoding/json" "fmt" "io/ioutil" "net/http ...

  8. JodaTimeUtil日期处理工具类(简单、实用)

    一.maven依赖 <!--joda time--> <dependency> <groupId>joda-time</groupId> <art ...

  9. SQL 必知必会·笔记<9>使用子查询

    子查询(subquery),即嵌套在其他查询中的查询. 1. 利用子查询进行过滤 SELECT 语句中,子查询总是从内向外处理.示例: SELECT cust_name, cust_contact F ...

  10. Hystrix隔离策略

    Hystrix的资源隔离策略分为两种:线程池和信号量.说到资源隔离,我们就要明白为什么需要资源隔离. 在一个分布式系统中,服务之间都是相互调用的,如下图所示:例如,我们容器(Tomcat)配置的线程个 ...