MountebankSwift

0.12.0

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.
MountebankSwift/MountebankSwift

What's New

0.12.0 - Completion api for usage without swift async

2024-04-19T15:39:36Z

What's Changed

  • Correct SPM version on Readme by @Nikoloutsos in #42
  • Add non async functions to the mountebank struct to use Mountebank without swift async. by @mat1th in #41
  • Update documentation for the mountebank struct; by @mat1th in #43

New Contributors

Full Changelog: 0.11.0...0.12.0

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.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Thu May 02 2024 22:42:15 GMT-0900 (Hawaii-Aleutian Daylight Time)