All Projects → Magiic → FireMock

Magiic / FireMock

Licence: MIT license
Mock and stub HTTP requests. Test your apps with fake data and files responses.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to FireMock

Timex
A test-friendly replacement for golang's time package
Stars: ✭ 53 (+112%)
Mutual labels:  mock, stub
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+40092%)
Mutual labels:  mock, stub
Cuckoo
Boilerplate-free mocking framework for Swift!
Stars: ✭ 1,344 (+5276%)
Mutual labels:  mock, stub
Dyson
Node server for dynamic, fake JSON.
Stars: ✭ 814 (+3156%)
Mutual labels:  mock, stub
sinon-mongoose
Extend Sinon stubs for Mongoose methods to test chained methods easily
Stars: ✭ 87 (+248%)
Mutual labels:  mock, stub
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (+52%)
Mutual labels:  mock, stub
Mimic
A mocking library for Elixir
Stars: ✭ 104 (+316%)
Mutual labels:  mock, stub
phake
PHP Mocking Framework
Stars: ✭ 464 (+1756%)
Mutual labels:  mock, stub
Mockingbird
Simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop against a service that is not complete or is unstable or just to reproduce planned/edge cases.
Stars: ✭ 149 (+496%)
Mutual labels:  mock, stub
Spy
Clojure/ClojureScript library for stubs, spies and mocks.
Stars: ✭ 131 (+424%)
Mutual labels:  mock, stub
Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+19224%)
Mutual labels:  mock, stub
aem-stubs
Tool for providing sample data for AEM applications in a simple and flexible way. Stubbing server on AEM, no separate needed.
Stars: ✭ 40 (+60%)
Mutual labels:  mock, stub
Swiftmockgeneratorforxcode
An Xcode extension (plugin) to generate Swift test doubles automatically.
Stars: ✭ 522 (+1988%)
Mutual labels:  mock, stub
Mocha
Mocha is a mocking and stubbing library for Ruby
Stars: ✭ 1,065 (+4160%)
Mutual labels:  mock, stub
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+336%)
Mutual labels:  mock, stub
Impersonator
Ruby library to record and replay object interactions
Stars: ✭ 100 (+300%)
Mutual labels:  mock, stub
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-44%)
Mutual labels:  mock, stub
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+1392%)
Mutual labels:  mock, stub
Mockit
A tool to quickly mock out end points, setup delays and more...
Stars: ✭ 1,534 (+6036%)
Mutual labels:  mock, stub
mocka
Mocka - The complete testing framework for LUA and Nginx
Stars: ✭ 26 (+4%)
Mutual labels:  mock, stub

FireMock

FireMock help to stub HTTP requests. If you are looking for an easy way to test your request or work with your server which is not ready so you are in a good place. Test your apps with fake response data and files with a short effort. With a short code you can set multiple mock and switch from them on runtime with a custom view provide by FireMock.

CocoaPods Compatible Platform Build Status Swift 4.2 License: MIT

Getting Started

To mock your requests you need to add files contains your structure response data (Json, XML, etc.) and install FireMock via Cocoapods.

Installing

CocoaPods

To integrate FireMock into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'FireMock'

Usage

Import FireMock

@import FireMock

Swift4 Only

For swift4, you need to add initialization on your AppDelegate.

class AppDelegate: UIResponder, UIApplicationDelegate {

    override init() {
        super.init()
        URLSessionConfiguration.classInit
    }

    //...
}

Enable FireMock

Add this code in your application to enable FireMock.

FireMock.enabled(true)

Implement FireMockProtocol

For each request you can associate a mock that will be used to return the desired response. Creating a mock is very simple. Implement the FireMockProtocol protocol and define its characteristics. All are optional except the mockFile function that expects the file to be used when the request is started.

For example if you have a service to fetch news with multiple possible responses :

enum NewsMock: FireMockProtocol {
    case success
    case successEmpty
    case failedParameters

    public var bundle: Bundle { return Bundle.main }

    public var afterTime: TimeInterval { return 0.0 }

    public var parameters: [String]? { return nil }

    public var headers: [String : String]? { return nil }

    public var statusCode: Int { return 200 }

    public var httpVersion: String? { return "1.1" }

    public var name: String? { return "Fetch News" }

    public func mockFile() -> String {
        switch self {
        case .success:
            return "success.json"
        case .successEmpty:
            return "successEmpty.json"
        case .failedParameters:
            return "failedParameters.json"
        }
    }
}

See FireMockProtocol for more information about properties.

Register

Last step, register one or more mocks for specific request. Specify for which url it is associated and if it is enabled. You can disable during compilation and enable it on runtime. You can also change the mock during runtime. This is described below.

FireMock.register(mock: NewsMock.success, NewsMock.successEmpty, httpMethod: .get, forURL: url, enabled: true)

If you want to be more flexible with url, you can register with a Regular Expression. It useful when you don't know exactly the url.

let regex = "https?://foo.com(/\\S*)?"
FireMock.register(mock: NewsMock.success, NewsMock.successEmpty, NewsMock.failedParameters, regex: regex, httpMethod: .get, enabled: true)

Host Condition

You can use your mock files with specific hosts only. If empty, mock works for all hosts.

FireMock.onlyHosts = ["foo.com"]

You can exclude hosts.

FireMock.excludeHosts = ["foo.com"]

Debug

Debug information about requests intercepted and enable or disable mocks. You can set 2 different levels information.

FireMock.debug(enabled: true)

Enable and Change Mock on runtime

All mocks can be enable or not on runtime. FireMock provide a ViewController that list all mocks registers by you. So it becomes easy to switch from one state to another without having to change code. You can also change the mock during runtime if you have registers 2 or more.

FireMock.presentMockRegisters(from: self, backTapped: nil)

Integrate with 3rd Party

FireMock handle automatically integration with 3rd Party network when it used URLSession API. FireMock uses Swizzling method to add FireURLProtocol in protocolClasses array from session configuration.

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].