BLACK FRIDAY SALE: 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: "")

        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")


            // Assert
            XCTAssertEqual(followers.count, 1)

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


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


Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

Learn more

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.