IOS -NSRunLoop in XCTest: How Do I Get A Run Loop to Work in A Unit Test?

前端 未结 2 481
你的背包
你的背包 2020-12-31 19:22

OK. I looked around, and didn\'t find an exact answer to my issue.

I am trying to test a timeout handler in a unit test (not the main run).

The issue seems t

2条回答
  •  没有蜡笔的小新
    2020-12-31 20:02

    Looks something like this in Swift 3.0 with XCTest.

    // somebody has to call the .fulfill() method on this variable 
    // to the expectation will fail after 25 seconds
    var asyncExpectation : XCTestExpectation!
    
    func testExample() {
        asyncExpectation = expectation(description: "longRunningFunction")
        self.waitForExpectations(timeout: 25.0) { (error) in
            if let error = error {
                print("Error \(error)")
            }
        }
        // more stuff here
    }
    

提交回复
热议问题