久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 KIF 框架模擬位置服務

How to mock location service using KIF-framework(如何使用 KIF 框架模擬位置服務)
本文介紹了如何使用 KIF 框架模擬位置服務的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我使用 KIF 框架(

可能是最好的:無需更改代碼.

I use KIF framework (http://github.com/kif-framework/KIF) for UI Tests and I need to mock location service.

The problem is location service starts BEFORE KIF method -beforeAll invoked. So it's too late to mock.

Any suggestions would be appreciated.

解決方案

In my KIF target I have a BaseKIFSearchTestCase : KIFTestCase, where I overwrite CLLocationManager`s startUpdatingLocation in a category.

Note that this is the only category overwrite I ever made as this is really not a good idea in general. but in a test target I can accept it.

#import <CoreLocation/CoreLocation.h>

#ifdef TARGET_IPHONE_SIMULATOR


@interface CLLocationManager (Simulator)
@end

@implementation CLLocationManager (Simulator)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

-(void)startUpdatingLocation 
{
    CLLocation *fakeLocation = [[CLLocation alloc] initWithLatitude:41.0096334 longitude:28.9651646];
    [self.delegate locationManager:self didUpdateLocations:@[fakeLocation]];
}
#pragma clang diagnostic pop

@end
#endif // TARGET_IPHONE_SIMULATOR



#import "BaseKIFSearchTestCase.h"

@interface BaseKIFSearchTestCase ()

@end

@implementation BaseKIFSearchTestCase
 //...

@end


Cleaner would be to have a subclass of CLLocationManager in your application target and another subclass with the same name in your test target that send fake location like shown above. But if this is possible depends on how your test target is set up, as it actually need to be an application target as Calabash uses it.


Yet another way:

  • in your project create another configuration "Testing", cloning "Debug"

  • add the Preprocessor Macro TESTING=1 to that configuration.

  • Subclass CLLocationManager

  • use that subclass where you would use CLLocaltionManger

  • conditionally compile that class

    #import "GELocationManager.h"
    
    @implementation GELocationManager
    -(void)startUpdatingLocation
    {
    
    #if TESTING==1
    #warning Testmode
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            CLLocation *fakeLocation = [[CLLocation alloc] initWithLatitude:41.0096334 longitude:28.9651646];
            [self.delegate locationManager:self didUpdateLocations:@[fakeLocation]];
        });
    
    #else
        [super startUpdatingLocation];
    #endif
    
    }
    @end
    

  • in your test targets scheme choose the new configuration


And yet another option:

Probably the best: no code needs to be changed.

這篇關于如何使用 KIF 框架模擬位置服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應用程序源代碼的情況下使用 Instruments 測試 iOS 應用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
How to provide login credentials to an automated android test?(如何為自動化的 android 測試提供登錄憑據?)
Android Test Automation tools(Android 測試自動化工具)
How to fix error quot;Could not detect Mac OS X Version from sw_vers output: #39;10.12 #39;quot; from Appium(如何修復錯誤“無法從 sw_vers 輸出檢測 Mac OS X 版本:10.12來自Appium)
How do you test an Android application across multiple Activities?(如何跨多個活動測試 Android 應用程序?)
主站蜘蛛池模板: 亚洲欧洲精品成人久久奇米网 | 亚洲乱码国产乱码精品精的特点 | 午夜激情国产 | 福利视频一区二区 | 日韩国产中文字幕 | 欧美a区| 中文字幕丁香5月 | 欧美成人免费在线视频 | 91麻豆精品国产91久久久久久久久 | 亚洲一区二区三区四区在线观看 | 99久久久久国产精品免费 | www国产亚洲精品久久网站 | 天天操天天插 | 久久99精品久久久久久 | 日韩欧美在线一区 | 欧美一级www片免费观看 | 四虎影院在线观看av | 又黄又色 | 国产精品毛片无码 | 国产一区二区三区四区三区四 | 日本亚洲欧美 | 国产欧美一区二区三区在线看 | 91久久精品日日躁夜夜躁国产 | 天天拍天天操 | 成人一区二区三区 | 亚洲成网站 | 精品久久久久国产免费第一页 | 亚洲电影第三页 | 91成人精品视频 | 日韩欧美大片在线观看 | 男人天堂av网 | 国产日韩精品一区二区三区 | 亚洲情视频 | 日韩亚洲一区二区 | 美女视频. | 亚洲3级 | 亚洲视频区| 综合激情网| 日韩视频精品在线 | 国产成人免费视频网站高清观看视频 | 国产成人高清 |