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

如何使用 KIF 框架模擬位置服務(wù)

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

我使用 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.

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

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

相關(guān)文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應(yīng)用程序源代碼的情況下使用 Instruments 測(cè)試 iOS 應(yīng)用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動(dòng)運(yùn)行/壓力測(cè)試 iOS 應(yīng)用程序以找出罕見 UI 錯(cuò)誤的原因?)
How to provide login credentials to an automated android test?(如何為自動(dòng)化的 android 測(cè)試提供登錄憑據(jù)?)
Android Test Automation tools(Android 測(cè)試自動(dòng)化工具)
How to fix error quot;Could not detect Mac OS X Version from sw_vers output: #39;10.12 #39;quot; from Appium(如何修復(fù)錯(cuò)誤“無法從 sw_vers 輸出檢測(cè) Mac OS X 版本:10.12來自Appium)
How do you test an Android application across multiple Activities?(如何跨多個(gè)活動(dòng)測(cè)試 Android 應(yīng)用程序?)
主站蜘蛛池模板: 亚洲在线播放 | 久久三级视频 | 欧美日韩亚洲综合 | 国产精品一区二区三区四区 | 国产一区二区三区久久 | 色婷av | www色| 四虎成人在线 | 亚洲综合视频在线观看 | 中文字幕免费视频 | 国产精品一区二区三区四区 | 青青草国产成人av片免费 | 日本一级一片免费视频 | 亚洲超碰在线 | 成人午夜在线视频 | 老司机午夜免费精品视频 | 久久久久久综合 | 日产久久视频 | 精品1区2区 | 欧美黄色一级大片 | 欧美精品成人 | 欧美福利在线 | 国产精品永久久久久久久久久 | 黄色录像一级片 | 午夜在线影院 | 国产色视频一区二区三区qq号 | 偷拍一区二区 | 久久久少妇 | 色中色综合 | 在线观看黄色片 | 高清一区二区 | 欧美亚洲视频 | 欧美日韩小视频 | 俺去俺来也在线www色官网 | 91福利网站| 久久精品视频一区二区 | 夜夜草导航| 久久久久蜜桃 | 国产草草| 亚洲午夜在线观看 | 在线观看小视频 |