Doppelgänger Swift
Doppelgänger Swift is a powerful and flexible tool for mocking and stubbing network requests in Swift. It provides an easy way to simulate network responses and test your network-dependent code without making actual API calls.
Features:
- Mock network responses with customizable data
- Stub network requests to return specific responses
- Simplify testing of network-dependent code
- Control and verify network behavior in tests
- Flexible and easy to integrate with existing projects
Installation:
You can install Doppelgänger Swift using CocoaPods. Add the following line to your project’s Podfile:
pod 'DoppelgangerSwift', '~> x.x.x'
Replace x.x.x
with the latest version of Doppelgänger Swift.
Usage:
To use Doppelgänger Swift, follow these steps:
- Import DoppelgangerSwift module into your class
- Create an instance of `Doppelganger`
- Configure the desired response(s) using `Doppelganger` methods
- Call the network request as usual, but using the `Doppelganger` instance to handle the request
- Access the response data or verify network behavior in your tests
Example:
import DoppelgangerSwift
// Create an instance of Doppelganger
let doppelganger = Doppelganger()
// Configure the mock response
doppelganger.mockResponse(for: "https://api.example.com/users", with: .success(data: jsonData))
// Call the network request using Doppelganger
doppelganger.send(request: myRequest) { result in
switch result {
case .success(let data):
// Access the response data
handleData(data)
case .failure(let error):
// Handle the error
handleError(error)
}
}
Contributing:
We welcome contributions to Doppelgänger Swift. If you find any issues or want to add new features, please submit a pull request. Make sure to follow the contributing guidelines.
License:
Doppelgänger Swift is released under the MIT license. See the license file for more information.