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.
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/
The documentation is available on the Swift Package Index website.
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.
- From the File menu, navigate through Swift Packages and select Add Package Dependency….
- Enter package repository URL:
https://github.com/MountebankSwift/MountebankSwift. - Confirm the version and let Xcode resolve the package.
- On the last dialog, update MountebankSwift's Add to Target column to a test target that will contain tests that use Mountebank.
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"),
]
)
]The MIT License (MIT). Please see License File for more information.
