A library for stubbing network requests in iOS/macOS/tvOS apps to test with fake data and simulate network conditions.
OHHTTPStubs is a library for iOS, macOS, and tvOS that intercepts and mocks network requests during development and testing. It allows developers to replace real API calls with predefined responses, enabling testing with fake data and simulated network conditions like slow connections or errors. This helps ensure apps behave correctly under various network scenarios without relying on live servers.
iOS, macOS, and tvOS developers writing unit or integration tests that involve network requests, especially those using NSURLSession, Alamofire, or similar networking frameworks.
Developers choose OHHTTPStubs for its simplicity, broad compatibility with iOS networking frameworks, and ability to simulate complex network conditions without modifying app architecture. Its support for both Swift and Objective-C, along with multiple installation methods, makes it a versatile tool for testing.
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
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 with any networking framework using Cocoa's URL Loading System, including NSURLSession, Alamofire, and AFNetworking, as stated in the README's compatibility section.
Provides dedicated Swift helpers for a more idiomatic experience alongside the Objective-C core, with support for multiple Swift versions from 3.x to 5.x.
Supports HTTPMessage, simple response files, and Mocktail format, offering flexibility in how stubs are defined and managed, as highlighted in the Key Features.
Available via CocoaPods, Carthage, and Swift Package Manager, with clear subspecs for different needs, making integration straightforward.
Cannot stub requests made with NSURLSessionConfiguration.backgroundSessionConfiguration, a limitation explicitly admitted in the 'Known limitations' section of the README.
Does not properly simulate data upload, ignoring HTTPBody and upload task data, which can skew test results for features involving file uploads or progress tracking.
Has a known bug with redirects that may cause nondeterministic null responses, as mentioned in the limitations, potentially affecting test reliability for redirect-heavy APIs.