Testing the asynchronous iOS module (waitForExpectations failing) in xCode 8 / Swift 3

I am updating my Cocoapod, which I developed to use Swift 3. Before I updated, all my asynchronous unit tests worked fine. But now, after the update, each of them immediately fails, and I have no idea why. Here is how each of them is structured:

override func setUp() {
        super.setUp()
        validationExpectation = expectation(description: "Validation")
}

.
.
.

func testSymbolRequest(){

        _ = MyCocoapod.makeSymbolRequest(symbol: "ABC", success: { (symbolObject) in
            self.validationExpectation.fulfill()
            XCTAssert(true)
        }) { (error) in
            self.validationExpectation.fulfill()
            XCTFail(error.description)
        }

        waitForRequestToFinish()
}

.
.
.

func waitForRequestToFinish(){
    waitForExpectations(timeout: 60.0) { (error) in
        if let error = error {
            XCTFail(error.localizedDescription)
        }
    }
}

The waitForExpectations function does not wait at all. He immediately ceases to be called. I also confirmed that this has nothing to do with my actual network code, and the queries work fine in my Cocoapod project example. I am using Alamofire. I don't think the problem is, but I thought it was worth mentioning. The error message that is being printed is an "unknown error."

+4
1

CocoaPod, , - , , waitForExpectations() . , , , :

  • pod , pod .

, waitForExpectations(), , , .

0

Source: https://habr.com/ru/post/1655758/


All Articles