久久久久久久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 應用程序?)
主站蜘蛛池模板: 色www精品视频在线观看 | 中文字幕在线视频精品 | 久久男人 | 中文在线观看视频 | 羞羞视频一区二区 | 国产一区二区三区四区在线观看 | 天天拍天天色 | 午夜日韩| 国产精品国产精品国产专区不卡 | 日韩久久成人 | 免费观看成人av | 国产999精品久久久 日本视频一区二区三区 | 男女羞羞免费视频 | 亚洲高清av | 国产片侵犯亲女视频播放 | 国产成人久久精品一区二区三区 | 青青久久 | 黄视频免费 | 中文精品一区二区 | 欧美精品久久久 | 国产精品视频一区二区三区四区国 | 1级毛片 | 精品亚洲一区二区 | 精品一区二区av | 日韩成人精品在线观看 | 久久成人国产精品 | 中文字幕在线一区二区三区 | 成人av在线播放 | 精品视频在线一区 | 中文字幕在线第二页 | 国产乱码精品一区二区三区五月婷 | 羞羞的视频网站 | 在线观看av网站 | 丁香一区二区 | www.久| 亚洲一级黄色 | 午夜精品三区 | 免费能直接在线观看黄的视频 | 美国a级毛片免费视频 | 999在线精品 | 久久国产精品99久久久大便 |