Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 2.54 KB

README.md

File metadata and controls

26 lines (17 loc) · 2.54 KB

UnitTestingNetworkWithStub_Demo

About

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

  1. 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 and Repository model.
  2. Show how to design a clean and generic NetworkRequest protocol that taking care of constructing the endpoint and handle network request, then serialize the data response into model using URLSession. Conformers just need to conform to NetworkRequest protocol and take advantage of Swift default protocol implementation, it can be customizable.
  3. Write test cases for NetworkRequest and our model using XCTest and Mockingjay for network stub.

Usage

Either check CodableSimple.playground or check separate files

TODO

  • Note to self: learn about URLProtocol to write a DIY network stub to even not using Mockingjay 🤔
  • UI testing

References