2

私はすべてを試しましたが、テストを成功させる唯一の方法は、テスト関数で実際に通知を送信することであり、これは目的に反しています。

ボタンがあります。ボタンをタップすると、通知が送信されます。この通知が送信されるかどうかを確認するには、expectationForNotification を使用するにはどうすればよいですか?

func testExample() {
    let app = XCUIApplication()
    let button = app.buttons["Button"]
    let expectation = expectationForNotification("TEST_NOTE", object: nil) {
        (notification: NSNotification!) -> Bool in

        print("SUCCESS")
        return true
    }

    button.tap()

    waitForExpectationsWithTimeout(5, handler: nil)
}
4

1 に答える 1

2

あなたはその期待に応えなければならないように見えます...

func testExample() 
{
     let app = XCUIApplication()
     let button = app.buttons["Button"]

     let expectation = expectationWithDescription("waiting for the tap")

      expectationForNotification("TEST_NOTE", object: nil)
      {
        notification in
        expectation.fulfill()
        return true
      }

      button.tap()

      waitForExpectationsWithTimeout(30)
      {
            error in 
            if let e = error
            {
                XCTFail("\(e.debugDescription)")
            }
       } 
}
于 2016-01-15T06:20:07.703 に答える