• 【读书笔记】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测试指南》

  • 相关阅读:
    [原]鼠标移至小图,自动显示相应大图
    [整理]asp.net导出Excel/Csv格式数据方案
    [整理]asp.net 上传大文件解决方案
    唐伯虎诗词
    [转]浅析软件项目管理中的10个误区
    [推荐]让SQL跑得更快
    [原]ASP.Net常用功能整理生成图片的缩略图
    [推荐]数据库性能优化
    SQL优化原则
    天地男儿
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/8182356.html
Copyright © 2020-2023  润新知