GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 Proxyman.

SPONSORED Debug 10x faster with Proxyman. Your ultimate tool to capture HTTPs requests/ responses, natively built for iPhone and macOS. You’d be surprised how much you can learn about any system by watching what it does over the network.

Try 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.