c语言xc比较大小写,XCTestAPI文档.docx

XCTestAPI文档

XCTest准备工作对于新项目,在新建项目界面勾选上UI Tests;对于旧项目,在项目界面点击菜单栏中的FileNewTarget…iOSTestiOS UITesting Bundle。sleepForTimeInterval:线程休眠[NSTread sleepForTimeInterval:1.0f];也可以使用sleep(3),OC兼容C语言。定义测试用例XCTestCase+ (void)setUp;在类中的第一个测试方法调用之前调用,区别于-(void)setUp:在每个测试方法调用之前都调用。+ (void)tearDown;在类中的最后一个测试方法完成后调用。区别于-(void) tearDown:在每个测试方法调用后都调用。异步测试表达式- (XCTestExpectation *)expectationWithDescription:(NSString *)description;指定时间内满足测试条件则测试通过,超时则输出description。- (void)testAsynExample {XCTestExpectation *exp = [self expectationWithDescription:@"这里可以是操作出错的原因描述。。。"];NSOperationQueue *queue = [[NSOperationQueue alloc]init];[queue addOperationWithBlock:^{ //模拟这个异步操作需要2秒后才能获取结果,比如一个异步网络请求 sleep(2); //模拟获取的异步操作后,获取结果,判断异步方法的结果是否正确 XCTAssertEqual(@"a", @"a"); //如果断言没问题,就调用fulfill宣布测试满足 [exp fulfill];}];//设置延迟多少秒后,如果没有满足测试条件就报错[self waitForExpectationsWithTimeout:3 handler:^(NSError * _Nullable error) { if (error) { NSLog(@"Timeout Error: %@", error); }}];}- (XCTestExpectation *)expectationForPredicate:(NSPredicate *)predicate evaluatedWithObject:(id)object handler:(XCPredicateExpectationHandler)handler;利用谓词计算,如果限定时间内满足条件则通过测试- (void)testThatBackgroundImageChanges { XCTAssertNil([self.button backgroundImageForState:UIControlStateNormal]); NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(UIButton * _Nonnull button, NSDictionary * _Nullable bindings) { return [button backgroundImageForState:UIControlStateNormal] != nil; }]; [self expectationForPredicate:predicate evaluatedWithObject:self.button handler:nil]; [self waitForExpectationsWithTimeout:20 handler:nil];}- (XCTestExpectation *)expectationForNotification:(NSString *)notificationName object:(id)objectToObserve handler:(XCNotificationExpectationHandler)handler;监听一个通知,如果在规定时间内正确收到通知则测试通过。- (void)testAsynExample1 { [self expectationForNotification:(@"监听通知的名称xxx") object:nil handler:nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"监听通知的名称xxx" object:nil]; //设置延迟多少秒后,如果没有满足测试条件就报错 [self waitForExpectatio

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值