Latest 1.1.0
Homepage https://github.com/justeat/Shock
License Apache 2.0
Platforms ios 9.0
Dependencies Swifter, GRMustache
Authors ,

Build Status
Version
License
Platform

A HTTP mocking framework written in Swift.

Summary

Shock lets you quickly and painlessly provided mock responses for web requests
made by your iOS app.

This is particularly useful for UI tests where you often want to receive
staged responses to allow reliable testing of all of your features.

It also provides an alternative to hitting live APIs and avoids the uncertainty
of receiving unexpected failures or response content as a result.

When used with UI tests, Shock runs its server within the UI test process and
stores all its responses within the UI tests target – so there is no need to
pollute your app target with lots of test data and logic!

Installation

Add the following to your podfile:

pod 'Shock', '~> x.y.z'

You can find the latest version on cocoapods.org

How does it work?

Shock aims to provide a simple interface for setting up your mocks.

Take the example below:

class HappyPathTests: XCTestCase {

    // MARK: - Scenario: Log in with non-existing user.

    func testHappyPath() {

        mockServer = MockServer(port: 6789, bundle: Bundle(for: HappyPathTests.self))

        let route = .simple(
            method: .GET,
            urlPath: "/my/api/endpoint",
            code: 200,
            filename: "my-test-data.json"
        )

        mockServer.setup(route: route)

        /* ... Your UI test code ... */
    }
}

Bear in mind that you will need to replace your API endpoint hostname with
‘localhost’ and the port you specify in the setup method during test runs.

e.g. https://localhost:6789/my/api/endpoint

This is most quickly accomplished by passing a launch argument to your app that
indicates which endpoint to use. For example:

let isRunningUITests = ProcessInfo.processInfo.arguments.contains("UITests")
if isRunningUITests {
    apiConfiguration.setHostname("http://localhost:6789/")
}

Shock Route Tester

Example app screenshot

Latest podspec

{
    "name": "Shock",
    "version": "1.1.0",
    "summary": "A HTTP mocking framework written in Swift.",
    "description": "Shock lets you quickly and painlessly provided mock responses for web requests made by your iOS app.",
    "homepage": "https://github.com/justeat/Shock",
    "license": {
        "type": "Apache 2.0",
        "file": "LICENSE"
    },
    "authors": {
        "Just Eat iOS team": "[email protected]",
        "Jack Newcombe": "[email protected]"
    },
    "source": {
        "git": "https://github.com/justeat/Shock.git",
        "tag": "1.1.0"
    },
    "social_media_url": "https://twitter.com/justeat_tech",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "5.0",
    "source_files": "Shock/Classes/**/*",
    "dependencies": {
        "Swifter": [
            "~> 1.4.6"
        ],
        "GRMustache": [
            "~> 7.3.2"
        ]
    }
}

Pin It on Pinterest

Share This