- To provide an easy way to mock network request with how we use our APIs
- To provide an easy way to mock APIs while early in development
NSNetworkingMocker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'NSNetworkingMocker'
MockURLProtocol is registered with URLProtocol as soon as a mock is added to the NetworkingMocker.mocks dictionary. After this has taken place it will be used automaticlly when using URLSession.shared.
To proxy a request when using a custom URLSession configuration you will need to do the following:
let config = URLSessionConfiguration.default
config.protocolClasses = [MockURLProtocol.self]
let session = URLSession(configuration: config)
let dataTask = session.dataTask(...
If you use Alamofire then you will need to do the following:
let configuration = URLSessionConfiguration.default
configuration.protocolClasses = [MockingURLProtocol.self]
let sessionManager = SessionManager(configuration: configuration)
ABTucanae, tucanae@icloud.com
NSNetworkingMocker is available under the MIT license. See the LICENSE file for more info.