xcode6 AsynchronousTesting 异步任务测试
2023-09-11 14:15:06 时间
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); } }]; }
相关文章
- 程序人生:月薪12K,高学历全职宝妈被骗6000元后幡然醒悟,转行测试逆风翻盘...
- 使用Portman、Postman和Newman自动化API测试
- 要做接口并发性能测试,总得先学会分析吧
- 敏捷开发实现测试自动化的6个步骤
- 技术分享 | 接口测试常用代理工具
- 测试面试 | 某个版本/模块问题很多,但上线时间紧迫怎么办?
- 技术分享 | 白盒测试方法论
- RPC接口测试技术-Tcp 协议的接口测试
- MAR-8ASM射频放大器测试
- 【转】构建高性能WEB站点之 吞吐率、吞吐量、TPS、性能测试
- 《软件测试》——GUI自动化测试篇
- 请教ChatGPT若干个关于测试开发职业发展的问题
- 软件测试技术之系统测试的具体测试类型
- Kail Linux渗透测试教程之网络扫描和嗅探工具Nmap
- web渗透测试----26、SQL注入漏洞--(1)原理篇
- 微信小程序~下拉刷新真机测试不弹回的处理办法
- ES6语法异步转同步(小程序中测试)
- selenium之使用unittest测试框架
- 测试三问——新手必看
- 移动开发云测试服务需求旺盛,Sauce Labs融资7000万美元