Coder Social home page Coder Social logo

MountebankSwift

A swift client library for the Mountebank - open source tool that provides test doubles over the wire. It provides all the api functionality to interact with a running Mountebank instance.

Mountebank logo holding a bottle with Swift's icon on it

Usage

Once installed, you need to start the Mountebank server with mb start. You can import the MountebankSwift module and setup MountebankSwift in your test.

import XCTest
import MountebankSwift

final class ExampleUITests: XCTestCase {

    private var mounteBank = Mountebank(host: .localhost)

    override func setUp() async throws {
        // Test if Mountebank is running if it failing please start Mountebank with `mb start`.
        try await mounteBank.testConnection()
    }

    override func tearDown() async throws {
        // Remove all imposters to have a clean Mountebank instance for the next tests.
        try await mounteBank.deleteAllImposters()
    }

    func testExample() throws {
        let stub = Stub(
            response: Is(statusCode: 201, body: .text("text")),
            predicate: .equals(Request(path: "/test"))
        )
        let imposter = Imposter(networkProtocol: .http, stubs: [stub])
        // Post the imposters to start testing against.
        try await mounteBank.postImposter(imposter: imposter)

        let app = XCUIApplication()
        app.launch()
    }
}

For more examples, see the demo app https://github.com/MountebankSwift/MountebankExampleApp/

Documentation

The documentation is available on the Swift Package Index website.

Installation

Using Xcode

Warning

By default, Xcode will try to add the MountebankSwift package to your project's main application/framework target. Please ensure that MountebankSwift is added to a test target instead, as documented in the last step, below.

  1. From the File menu, navigate through Swift Packages and select Add Package Dependency….
  2. Enter package repository URL: https://github.com/MountebankSwift/MountebankSwift.
  3. Confirm the version and let Xcode resolve the package.
  4. On the last dialog, update MountebankSwift's Add to Target column to a test target that will contain tests that use Mountebank.

Using Swift Package Manager

To add MountebankSwift to a project that uses SwiftPM, you can add it as a dependency in Package.swift:

dependencies: [
  .package(
    url: "https://github.com/MountebankSwift/MountebankSwift",
    from: "0.0.0"
  ),
]

Next, add MountebankSwift as a dependency of your test target:

targets: [
  .target(name: "MyExampleApp"),
  .testTarget(
    name: "MyExampleAppTests",
    dependencies: [
      "MyExampleApp",
      .product(name: "MountebankSwift", package: "MountebankSwift"),
    ]
  )
]

License

The MIT License (MIT). Please see License File for more information.

Mountebank Swift's Projects

mountebankswift icon mountebankswift

A Swift client library for the Mountebank - open source tool that provides test doubles over the wire. It provides the all api functionality to interact with a Mountebank instance running.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.