{"id":17686606,"url":"https://github.com/vinhnx/unittestingnetwork","last_synced_at":"2025-03-30T20:48:16.213Z","repository":{"id":148466778,"uuid":"145391187","full_name":"vinhnx/UnitTestingNetwork","owner":"vinhnx","description":"Demo on how to build a simple and testable network suite in Swift, using Mockingjay.","archived":false,"fork":false,"pushed_at":"2019-08-13T08:21:25.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T23:57:17.291Z","etag":null,"topics":["cocoapods","codable","design","generic","mockingjay","stub","swift","unittesting","urlsession"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinhnx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-20T08:48:22.000Z","updated_at":"2020-04-11T20:30:31.000Z","dependencies_parsed_at":"2023-05-20T06:45:37.804Z","dependency_job_id":null,"html_url":"https://github.com/vinhnx/UnitTestingNetwork","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinhnx%2FUnitTestingNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinhnx%2FUnitTestingNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinhnx%2FUnitTestingNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinhnx%2FUnitTestingNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinhnx","download_url":"https://codeload.github.com/vinhnx/UnitTestingNetwork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246379385,"owners_count":20767696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","codable","design","generic","mockingjay","stub","swift","unittesting","urlsession"],"created_at":"2024-10-24T10:45:25.137Z","updated_at":"2025-03-30T20:48:16.193Z","avatar_url":"https://github.com/vinhnx.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnitTestingNetworkWithStub_Demo\n\n### About\n\nThis is a sample demo on how to build a simple and tested network suite using just vanila Foundation and the power of Swift programming language. Only to use `Mockingjay` third party library for network stub in unit test. This can be improved.\n\n0. Show how easy it is to design a model using `Codable` protocol from Swift 4+. So we no longer need to use any third party model mapping library, now that the Swift compiler will take care of it. Check [`User`](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2/Model/User.swift) and [`Repository`](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2/Model/Repository.swift) model. \n1. Show how to design a clean and generic [`NetworkRequest`](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2/Network/NetworkRequest.swift) protocol that taking care of constructing the endpoint and handle network request, then serialize the data response into model using `URLSession`. [`Conformers`](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2/Network/GithubUserRequest.swift) just need to conform to `NetworkRequest` protocol and take advantage of Swift default protocol implementation, it can be [customizable](https://github.com/vinhnx/iOS-notes/issues/47).\n2. Write test cases for [NetworkRequest](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2Tests/NetworkRequestTests.swift) and our [model](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/blob/master/UnitTestingNetworkWithStub_2Tests/UserTests.swift) using `XCTest` and `Mockingjay` for network stub.\n\n### Usage\n\nEither check [CodableSimple.playground](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/tree/master/CodableSimple.playground) or check [separate files](https://github.com/vinhnx/UnitTestingNetworkWithStub_Demo/tree/master/UnitTestingNetworkWithStub_2)\n\n### TODO \n\n+ Note to self: learn about `URLProtocol` to write a DIY network stub to even not using `Mockingjay` 🤔\n+ UI testing\n\n### References\n\n- https://api.github.com/users/{user_name}\n- https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types\n- https://www.swiftbysundell.com/posts/writing-unit-tests-in-a-swift-playground\n- http://hoangtran.me/ios/testing/2016/09/12/unit-test-network-layer-in-ios/\n- https://useyourloaf.com/blog/swift-codable-with-custom-dates/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinhnx%2Funittestingnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinhnx%2Funittestingnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinhnx%2Funittestingnetwork/lists"}