Should we write unit tests for network classes?

final class ComputerAPITests: XCTestCase { var sut: ComputerAPIProtocol!
var apiRequestMock: APIRequestProtocol!
override func setUpWithError() throws {
apiRequestMock = APIRequestProtocolMock()
sut = ComputerAPI(apiRequest: apiRequestMock)
}
func testDecodeResponse() async throws {
let response = try await sut.fetchRandomComputer()
XCTAssertNotNil(response)
}
}
final class APIRequestProtocolMock: APIRequestProtocol { private enum Constants {
static let successResponse = "Based on your api and model"
}
func get(request: URLRequest) async throws -> Result<Data, Error> {
return .success(Constants.successResponse.data(using: .utf8)!)
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store