LoginSignup
0
1

More than 5 years have passed since last update.

非同期通知が来ない事を確認するテストを行う

Last updated at Posted at 2018-12-01

はじめに

iOSのユニットテストフレームワークには通知、KVOといった非同期処理のテストを書くメソッドが準備されています。
ただ、非同期のトリガーそのものが発火しない事を確認するためのテストを書きたい事があるかと思います。

その時は以下のコードを書く事で実現することができます。

実際のコード例


        let expectation = XCTNSNotificationExpectation(name:HogehogeNotification)

        テストコード
        ...

        // 通知が来ない事をテストにするはisInvertedをtrueにセットする。
        expectation.isInverted = true
        // タイムアウトすればテストが成功
        wait(for: [expectation], timeout: 0.01)

0
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
0
1