• xcode6 AsynchronousTesting 异步任务测试


    xcode集成了非常方便的测试框架,XCTest

    在xcode6之后,提供了 <XCTest/XCTestCase+AsynchronousTesting.h>

    利用此我们可以直接在XCTest里面测试一些异步的任务,比如异步网络请求

    如下示例

    - (void)testExample {
    
        
        XCTestExpectation *exception = [self expectationWithDescription:@"TestException"];
        
        [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://httpbin.org/get"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            
            XCTAssertNil(connectionError,@"connectionError should nil");
            NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
            [exception fulfill];
            
        }];
        
        [self waitForExpectationsWithTimeout:5.0f handler:nil];
    }

    另外 可以使用 measureBlock 测试性能:

    - (void)testPerformanceExample {
        // This is an example of a performance test case.
        [self measureBlock:^{
            
            for (int i = 0; i < 10; i++) {
                NSLog(@"%d",i);
            }
        }];
    }
  • 相关阅读:
    Lucas定理及其应用
    HDU 5044 TREE
    HDU 5033 Building
    Codeforces Round #238 (Div. 1)
    hdu 4878 ZCC loves words AC自动机+中国剩余定理+快速幂
    HDU 5015 233 Matrix
    HDU 5008 Boring String Problem
    ZOJ 3817 Chinese Knot
    使用AutoMapper
    多租户概念以及FreeLink多租户设计思想
  • 原文地址:https://www.cnblogs.com/cocoajin/p/4679446.html
Copyright © 2020-2023  润新知