MountebankSwift

0.11.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.11.0

2024-04-08T11:42:14Z

What's Changed

  • Set default argument for Imposter.networkProtocol by @teameh in #36
  • Implement Sendable where possible in preperation of swift 6. by @mat1th in #33 & #39
  • make Proxy and PredicateParameters properties public for better docs by @teameh in #35
  • Swift packages: Bump github.com/pointfreeco/swift-snapshot-testing from 1.15.4 to 1.16.0 in the dependencies group by @dependabot in #38
  • Write stubs to disk into extension by @teameh in #37
  • Recreatable thread safe by @teameh in #40

Full Changelog: 0.10.0...0.11.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()
    }
}

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: "1.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: Fri Apr 19 2024 07:38:19 GMT-0900 (Hawaii-Aleutian Daylight Time)