A Swift library for mocking Alamofire and URLSession requests using a custom URLProtocol without modifying production code.
Mocker is a Swift library that enables developers to mock network requests for unit testing by intercepting URLSession and Alamofire calls through a custom URLProtocol. It allows offline testing of data-dependent features by simulating API responses with custom data, status codes, and delays.
iOS and macOS developers writing unit tests for networking code, particularly those using URLSession or Alamofire and needing reliable, offline test scenarios.
Developers choose Mocker because it integrates seamlessly with existing networking code without modifications, supports both URLSession and Alamofire, and offers flexible mocking features like delayed responses, error simulation, and query ignoring for dynamic URLs.
Mock Alamofire and URLSession requests without touching your code implementation
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Works directly with Alamofire by registering MockingURLProtocol in the session configuration, as shown in the README, without altering production code.
Supports delayed responses, error simulation, and redirects, allowing testing of edge cases like timeouts or authentication flows with specific data.
Enables mocking of URLs with dynamic query strings by ignoring the query, useful for testing APIs with timestamps or UUIDs, as demonstrated in the examples.
Provides onRequest and completion handlers, simplifying test assertions without extra boilerplate, and includes expectation helpers for XCTest integration.
Relies on custom URLProtocol, which can interfere with other URLSession uses if not managed via opt-in/opt-out modes, potentially causing side effects in shared sessions.
Requires developers to create and maintain mock data files manually, which can be cumbersome for large APIs or frequent response changes.
Lacks native support for mocking GraphQL or other specific API types; developers must handle custom data and content types manually, as admitted in the README for XML examples.