スウィフトヘルパーテストコード
// 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
する必要がありますあなたのアプリを別のソースから設定を取得することをサポートする。次に、テストケースで設定ソースを指定できます。簡単な解決方法は、辞書オブジェクトを渡す方法です。これはplistがやっていることです。 – Michael
michealが言ったように、あなたは辞書を作り、それを使うことができます。辞書を渡してplistファイルから読み込みたくない場合は、その辞書をplistファイルに書き込んでください。 –