OSS TanbouSign in with GitHub

stub NSURLSession-style requests in tests with fixtures, status codes, headers, and delays

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
5,066
Primary language
Objective-C
License
MIT
Repository last updated
May 9, 2024
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.

Sources: [4][3][2]

Official sources

  1. [1]AliSoftware/OHHTTPStubs — GitHub repository(2026-10-06)
  2. [2]OHHTTPStubs 9.1.0 — README(2026-10-06)
  3. [3]OHHTTPStubs 9.1.0 — Package.swift(2026-10-06)
  4. [4]OHHTTPStubs 9.1.0 release(2026-10-06)
  5. [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. 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. 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. 3

    Remove stubs after the test

    Clear installed stubs in tearDown or equivalent so state does not leak to later tests.

    HTTPStubs.removeAllStubs()
Check the official README

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

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
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?