ios – 如何在Obj C中编写没有完成块的异步方法的单元测试

ios – 如何在Obj C中编写没有完成块的异步方法的单元测试,第1张

概述我有一个在内部调用API的方法.该方法没有任何完成处理程序. -(void) methodToBeTested{ [self callAPIWithCompletionHandler:^(NSArray *data,NSError *error) { //Here I get the response and sets the models. }]; 我有一个在内部调用API的方法.该方法没有任何完成处理程序.

-(voID) methodToBeTested{    [self callAPIWithCompletionHandler:^(NSArray *data,NSError *error)     {         //Here I get the response and sets the models.     }];}

现在我需要在API调用之后测试模型集的方法“methodToBeTested”.

有什么建议?

解决方法 例:

XCTestExpectation *documentOpenExpectation = [self expectationWithDescription:@"document open"];    NSURL *URL = [[NSBundle bundleForClass:[self class]]                              URLForResource:@"Testdocument" withExtension:@"mydoc"];    UIdocument *doc = [[UIdocument alloc] initWithfileURL:URL];    [doc openWithCompletionHandler:^(BOol success) {        XCTAssert(success);        [documentOpenExpectation fulfill];    }];    [self waitForExpectationsWithTimeout:1 handler:^(NSError *error) {        [doc closeWithCompletionHandler:nil];    }];}

查看使用Xcode文档测试下的异步 *** 作的编写测试. https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

总结

以上是内存溢出为你收集整理的ios – 如何在Obj C中编写没有完成块的异步方法的单元测试全部内容,希望文章能够帮你解决ios – 如何在Obj C中编写没有完成块的异步方法的单元测试所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1030737.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存