zoukankan      html  css  js  c++  java
  • 【读书笔记】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测试指南》

  • 相关阅读:
    vue的选项
    css(3)基础知识查漏补缺
    总结获取网页相关的一些宽高
    vue的全局api(二)
    vue的全局api
    vue的内部指令
    Java File
    Java File IO学习笔记
    systemctl介绍
    java学习笔记一(20180319)
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/8182356.html
Copyright © 2011-2022 走看看