LoginSignup
1
1

More than 5 years have passed since last update.

コード内で現在ユニットテスト中か否かを判定する。

Last updated at Posted at 2018-12-01

はじめに

現在、アプリとして動いているか、あるいはテスト中かを判定したい事があると思います。ただ、iOSにはそれ用のメソッドが準備されていません。これはマクロを定義する必要があるのか?と嘆く必要ありません。それなりにエレガントな解決方法があります。

実際のコード

以下のようにXCTestCaseが存在するか否かを調べる事で判定することができます。

   Class testSuite = NSClassFromString(@"XCTestCase");
   return testSuite != nil;
1
1
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
1
1