LAST CHANCE: Save 50% on all my Swift books and bundles! >>

SOLVED: URL Asynchronous testing, unexpected breakpoint

Forums > Swift

Hey guys. I am learning how to do testing.

I am having a little issue with that code. It throws a breakpoint at XCTAssertEqual() line (I've checked and I ma sure that no breakpoint was set by me). Test won't go any further no matter what I do, and testing will never end.

I have checked response's status code and existence of an error in seperate test. Follower is a Class that conforms to FollowerProtocol. (I am following some examples from Swift Testing book by Paul Hudson). Anyone happens to know what am I doing wrong here? Many thanks.

 func testFetchedFollowersFromGithubEqualTo1() {
        // Assert
        let sut         = URLSession(configuration: .default)
        let url         = URL(string: "https://api.github.com/users/jmgawecki/followers?per_page=1&page=1")

        let expectation = XCTestExpectation(description: "Completion handler invoked")

        var followers:  [Follower] = []
        let decoder     = JSONDecoder()

        // Act
        let dataTask    = sut.dataTask(with: url!) { (data, response, error) in
            guard let data = data else { return }

            do {
                decoder.keyDecodingStrategy = .convertFromSnakeCase
                followers                   = try decoder.decode([Follower].self, from: data)
            } catch {
                XCTFail("Catch block error")
            }

            expectation.fulfill()

            // Assert
            XCTAssertEqual(followers.count, 1)
        }
        dataTask.resume()

        wait(for: [expectation], timeout: 5)
    }

3      

Solved, breakpoints are automatic for those tests if the xtcasssert is not passing.

3      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.