Skip to content

andrewspinks/PactObjectiveCExample

Repository files navigation

Example Pact ObjectiveC project using Git Submodules

Build Status

See the Pact Swift library for more details. PactConsumerSwift library

Installation with CocoaPods

Homebrew

brew tap pact-foundation/pact-ruby-standalone brew install pact-ruby-standalone

This will install the following tools:

pact pact-broker pact-message pact-mock-service pact-provider-verifier pact-publish pact-stub-service

Manually

Alternatively you can download and install the [pact-ruby-standalone][pact-ruby-standalone-releases] archives for your platform and install as per installation instructions written in [Pact Ruby Standalone release notes][pact-mock-service-standalone-installation].

Add the Pod

Add to your Test target in your Podfile

target 'MyProjectTests' do
  pod 'PactConsumerSwift'
end

Setup your Test Target to run the pact server before the tests are run

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/installed-pact-ruby-standalone/pact/bin:$PATH
    "$SRCROOT"/Pods/PactConsumerSwift/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

  • Under Test, Post-actions add a Run Script Action to stop the pact service.

    PATH=/path/to/pact-mock-service/binary:$PATH
    "$SRCROOT"/Pods/PactConsumerSwift/scripts/stop_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

Objective-C Caveat: Your Test Target Must Include At Least One Swift File

The Swift stdlib will not be linked into your test target, and thus PactConsumerSwift will fail to execute properly, if you test target does not contain at least one Swift file. If it does not, your tests will exit prematurely with the following error:

*** Test session exited(82) without checking in. Executable cannot be
loaded for some other reason, such as a problem with a library it
depends on or a code signature/entitlements mismatch.

To fix the problem, add a blank file called BlankClass.swift to your test target:

// BlankClass.swift

import PactConsumerSwift

Writing tests

See PactTests.m for examples of writing Pact tests in Objective C. For Swift see Pact Swift Example

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published