Nothing Special   »   [go: up one dir, main page]

Skip to content

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.

License

Notifications You must be signed in to change notification settings

MountebankSwift/MountebankSwift

Repository files navigation

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •