LoginSignup
2
2

More than 5 years have passed since last update.

シングルトンの初期化をテストするには

Posted at

テストは増えてくると実行順が変わるので、シングルトンの初期化がうまくいっているかをテストするには、いったんシングルトンを棄てなければならない。

そこで、シングルトンに以下のメソッドを生やす。

Location.m
+ (void)resetSharedInstance {
    _instance = nil;
}

あとはテストする。

LocationTest.m
- (void)testInit
{
    [Location resetSharedInstance]; // これでシングルトンをリセットする
    GHAssertEquals([Location sharedManager].coodinate.latitude, 35.681382, @"位置情報の初期値は東京駅の座標である(緯度)");
    GHAssertEquals([Location sharedManager].coodinate.longitude, 139.766084, @"位置情報の初期値は東京駅の座標である(経度)");
}
2
2
0

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
2
2