【读书笔记】iOS-OCUnit-单元测试

一,新建立一个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测试指南》

转载于:https://www.cnblogs.com/yang-guang-girl/p/8182356.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值