2016-10-04 4 views
0

アプリケーションは、ApplicationConfig.plistファイルで指定されたサービスからコンテンツを取得します。 4つの異なるApplicationConfig.plistファイルを使用するには4つのXCTestCasesが必要です。それを設定する最良の方法は何ですか?XCTests間でApplicationConfig.plistsを変更するには

これらのテストはパフォーマンステストであるため、テストが開始されるとサービスを変更できないため、最初の起動前にサービスを設定ファイルから設定する必要があります。

+1

する必要がありますあなたのアプリを別のソースから設定を取得することをサポートする。次に、テストケースで設定ソースを指定できます。簡単な解決方法は、辞書オブジェクトを渡す方法です。これはplistがやっていることです。 – Michael

+1

michealが言ったように、あなたは辞書を作り、それを使うことができます。辞書を渡してplistファイルから読み込みたくない場合は、その辞書をplistファイルに書き込んでください。 –

答えて

0

スウィフトヘルパーテストコード

// You will need to get the bundle path of the test app to pass to the main app 
func getBundlePath() -> String 
{ 
    let bundle = Bundle.main 
    let bundlePath = bundle.builtInPlugInsPath! + "/" + ((bundle.infoDictionary?["CFBundleName"])! as! String) + ".xctest" 
    return bundlePath 
} 

// Launch the app and pass it the path to the test app and the name of the plist you want to use 
func launchAppWithPlist(_ plistName: String) -> XCUIApplication 
{ 
    // Launch the app between tests 
    let app = XCUIApplication() 
    app.launchEnvironment = ["use_custom_plist" : plistName, "path_to_test_app" : getBundlePath()] 
    app.launch() 

    return app 
} 

スウィフトテスト

launchAppWithPlist("YourPlistFileName") 

ApplicationDelegate(のObjective C)

static NSString* const kCustomAppConfigKey = @"use_custom_plist"; 
static NSString* const kPathToTestAppKey = @"path_to_test_app"; 

NSDictionary *environment = [[NSProcessInfo processInfo] environment]; 
NSString *pathToConfigFile = [environment[kCustomAppConfigKey] lastPathComponent]; 
NSString *pathToTestBundle = [[[environment[kPathToTestAppKey] pathComponents] valueForKey:@"description"] componentsJoinedByString:@"/"]; 
NSBundle *bundle = [NSBundle bundleWithPath:pathToTestBundle]; 

そこから、あなたが取得するために(テスト)のバンドルを使用することができます内側にplier

関連する問題