See the Pact Swift library for more details. PactConsumerSwift library
Install the pact-ruby-standalone as per installation instructions.
- Add
github "DiUS/pact-consumer-swift
to your Cartfile - Follow the Carthage guidelines for building and adding a framework with Carthage: Carthage
- Add the
PactConsumerSwift.framework
to your test target - For iOS projects, you must add a run script to copy the frameworks to the correct location. See the Carthage documentation for more info.
Modify the Test Target's scheme to add scripts to start and stop the pact server when tests are run.
-
From the menu
Product
->Scheme
->Edit Scheme
-
Under Test, Pre-actions add a Run Script Action Add a Run Script Action with the following NB: the PATH variable should be set to the location of the pact-mock-service binary - you can find the path using
which pact-mock-service
PATH=/path/to/pact-mock-service/binary:$PATH "$SRCROOT"/Carthage/Checkouts/pact-consumer-swift/scripts/start_server.sh
- Make sure you select your project under
Provide the build settings from
, otherwise SRCROOT will not be set which the scripts depend on
- Make sure you select your project under
-
Under Test, Post-actions add a Run Script Action to stop the pact service.
PATH=/path/to/pact-mock-service/binary:$PATH "$SRCROOT"/Carthage/Checkouts/pact-consumer-swift/scripts/stop_server.sh
See PactSwifExampleTests.swift for examples of writing Pact tests in Swift. For Objective-C see Pact ObjectiveC Example