On this page
Overview
OHHTTPStubs is a testing library that intercepts requests using Apple's URL Loading System. Matchers can target hosts and paths and return fixtures, custom status codes, headers, and response delays for unit tests and degraded-network scenarios.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Inject fixture responses with request matchers
Matchers such as isHost select requests and return fixture files or custom responses. The stubs work with NSURLSession and networking libraries built on the Cocoa URL Loading System, including Alamofire.
Sources: [2]
Test slow networks and error paths through delays, status codes, and headers
Tests can vary response time, status codes, and headers in addition to payloads. The README recommends removing installed stubs after each test so state does not leak into later cases.
Sources: [2]
Best fit
Fits deterministic tests for API clients and loading, success, and error UI states
It is useful when iOS tests should reproduce network behavior from local fixtures without depending on backend availability.
Sources: [2]
Before adoption
The latest release is from 2020, and background sessions and upload simulation are limited
The latest GitHub release is 9.1.0 from December 2020 and Package.swift uses Swift tools 4.0. The README states that background NSURLSession configurations cannot be stubbed and upload progress is not simulated. Keep it in test or DEBUG configurations and verify compatibility with current Swift/Xcode.
Official sources
- [1]AliSoftware/OHHTTPStubs — GitHub repository(2026-10-06)
- [2]OHHTTPStubs 9.1.0 — README(2026-10-06)
- [3]OHHTTPStubs 9.1.0 — Package.swift(2026-10-06)
- [4]OHHTTPStubs 9.1.0 release(2026-10-06)
- [5]OHHTTPStubs MIT license(2026-10-06)
Supplemental curator note
OHHTTPStubs fits deterministic API-client and loading/error-state tests without a live backend. The latest release is from 2020, so keep it in test or DEBUG configurations and verify current Swift/Xcode compatibility.
Try it in 3 steps
- 1
Add OHHTTPStubs 9.1.0 to the test target
Use the OHHTTPStubsSwift product from tests and verify the older release against the current toolchain.
.package(url: "https://github.com/AliSoftware/OHHTTPStubs.git", exact: "9.1.0") - 2
Stub requests matching a host
Intercept URL Loading System requests for the selected host and return a local JSON response.
import OHHTTPStubs import OHHTTPStubsSwift stub(condition: isHost("api.example.com")) { _ in HTTPStubsResponse(jsonObject: ["ok": true], statusCode: 200, headers: nil) } - 3
Remove stubs after the test
Clear installed stubs in tearDown or equivalent so state does not leak to later tests.
HTTPStubs.removeAllStubs()
Growth
Growth trends · Last 30 days
5,066 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 0
- Open PRs
- 12
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- ios
- stubbing
- network
- swift
- objective-c
- stub
- ohhttpstubs
- mock
- mock-server
- mocking
- Stars
- 5,066
- Forks
- 598
- Watchers
- 107
- Open issues
- 47
- Contributors
- 60
- Owner type
- User
- Primary language
- Objective-C
- License
- MIT
- Repository last updated
- May 9, 2024
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- REST Assured7,141 Stars
3 shared tag(s) · 1 shared category(s)
test REST APIs from Java with a DSL for requests, status, headers, and JSON/XML assertions
Java - http4k2,791 Stars
3 shared tag(s) · 1 shared category(s)
serve, consume, and test HTTP services as Kotlin functions
Kotlin - Jest45,500 Stars
2 shared tag(s) · 2 shared category(s)
Combine assertions, mocks, watch mode, snapshots, coverage, and worker isolation in one JavaScript test runner
TypeScript - Testify26,222 Stars
2 shared tag(s) · 2 shared category(s)
augment Go's standard testing package with assertions, mocks, and suites
Go - Appium22,046 Stars
2 shared tag(s) · 2 shared category(s)
automate end-to-end tests for Android, iOS, and desktop apps through WebDriver-compatible APIs
TypeScript - Catch221,508 Stars
2 shared tag(s) · 2 shared category(s)
write C++ unit tests, BDD scenarios, and micro-benchmarks in one test framework and integrate them with CMake and CTest
C++
Report incorrect information
Tell us if any listing information is incorrect or outdated.