LoginSignup
0

More than 5 years have passed since last update.

テスト用のシミュレータを厳格に判定する。

Last updated at Posted at 2019-01-12

はじめに

 ViewやViewControllerと言った環境依存性が高い部分のユニットテストを行う場合、対象のOSのバージョンおよび(シミュレータの)端末等を明確化しておかないと、
特にチーム開発で新規参入者が何をやっても通らないテストではまります。

解決策

テストホストアプリケーションに以下の形で強制終了させるコードを書きます。



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  NSDictionary<NSString *, NSString *> *environment = [NSProcessInfo processInfo].environment;
    NSAssert([environment[@"SIMULATOR_RUNTIME_VERSION"] isEqualToString:@"11.4"], @"iOS 11.4シミュレータ上で動いていない");
    NSAssert([environment[@"SIMULATOR_DEVICE_NAME"] isEqualToString:@"iPhone 8"], @"iPhone 8シミュレータ上で動いていない");

    return YES;
}


Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0