一,新建立一个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. Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)

    C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  2. Java 中的 HttpServletRequest 和 HttpServletResponse 对象

    HttpServletRequest对象详解 javax.servlet.http.HttpServletRequest是SUN制定的Servlet规范,是一个接口.表示请求,“HTTP请求协议”的完 ...

  3. scrapy Data flow

    The data flow in Scrapy is controlled by the execution engine, and goes like this:1. The Engine gets ...

  4. python之装饰器(decorator)

    python的装饰器如果用得好,那是大神,用的不好最好别用... 装饰器(decorator)主要包含俩大属性: 1.不能改变原有函数的调用方式 2.不能改变原有函数的代码 第一个表示,我不需要改变原 ...

  5. Android模拟微信主页面的Demo

    Android模拟微信主页面的Demo 效果图如下: 项目结构图如下: ContanctFragment: package com.demo.moniwexin; import android.app ...

  6. 区块链 + 大数据:EOS存储

    谈到区块链的存储,我们很容易联想到它的链式存储结构,然而区块链从比特币发展到今日当红的EOS,技术形态已经演化了10年之久.目前的EOS的存储除了确认结构的链式存储以外,在状态存储方面有了很大的进步, ...

  7. C语言第五讲,语句 顺序循环选择.

    C语言第五讲,语句 顺序循环选择. 一丶语句的简明了解 我们知道,在编写C语言程序的时候,代码是顺序执行的. 从上往下执行. 但是我们可以控制流程的. 在控制之前,我们要先熟悉什么是语句. 相比大家学 ...

  8. Algolia使用教程 , 超详细傻子看都会

    框架描述 发现网上Algolia这块的资料较少,就花了点时间从官网上整理了下,总结了几项常用的功能用法. 现在比较有名的Algolia提供了云搜索的服务.具体办法是我们将数据库的信息以JSON的格式上 ...

  9. 一个简单有趣的Python音乐播放器

    (赠新手,老鸟绕行0.0) Python版本:3.5.2 源码如下: __Author__ = "Lance#" # -*- coding = utf-8 -*- #导入相应模块 ...

  10. python字典操作和内置方法

    一 字典基本介绍 python中只有字典是映射结构,通过key取值,并且key是不可变数据类型,而value可以是任意数据类型. 字典通过一个花括号,里面存放key:value的数据结构来定义.理论上 ...