16
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Xcode で Test コードを走らせると、appが起動してしまっていやだ

Last updated at Posted at 2014-05-19

Xcodeで iOS appを作成しているとする。
cmd + u で test を 走らせるたびに、ちゃんとappが起動してしまって、起動プロセスが重いappの場合これが、ストレスになる。
main.m に ちょっと細工をする。

int main(int argc, char *argv[])
{
    int ret = -1;
    @autoreleasepool
    {
        BOOL inTests = (NSClassFromString(@"XCTest") != nil);
        if(inTests) {
            ret = UIApplicationMain(argc, argv, nil, @"MYTestAppDelegate");
        }
        else 
        {
            ret = UIApplicationMain(argc, argv, nil,@"MYAppDelegate");
        }
        return ret;
    }
}

XCTestというClassはXCTest.frameworkで定義されており、このframeworkをtargetに含んでいる方だけが inTests = YES となる。

MYTestAppDelegate は UIApplicationDelegateを継承している空実装class。XcodeでNew Fileして放っておく。
結論:Xcode で Test コードを走らせると、appが起動してしまっていやだけど、appは起動します。だから出来るだけ軽く起動するようにします。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?