Pravesh
04/20/2023, 12:24 AMMarko (IttyBittyApps / pact-swift)
04/20/2023, 11:21 PMsurpher/PactSwift
and DiUS/pact-consumer-swift
both link to demo projects in GitHub you can have a look.
Writing tests for those is pretty much identical apart from setup.
1. pact-consumer-swift
a. you need to get a pact-ruby-standalone
- you can install via Homebrew. And doco links you to it.
b. you need to set up your scheme to trigger startup and shutdown of pact-ruby-standalone
- again, the doco on GitHub and examples should help you find an example how to do it
c. you DiUS/pact-consumer-swift
to your project via a dependency manager
d. you set an env var
(in your test scheme) for your location where you want the Pact contract to be written to
e. you write your pact tests (same approach as for any other Pact implementation) - there are heaps of examples of how pact tests look like in demo projects
f. run your tests
g. if they pass, Pact contract is found in location defined in your env var
h. after that it’s either automate that on CI to upload Pact contract(s) to Pact Broker, tag/version/ them, … etc, or share them via Slack/email with your provider team,… Depends on the process you’ve agreed on.
2. PactSwift
a. you add surpher/PactSwift
to your project via SPM
b. you set an env var
(or pass the URL
to folder) at mockService
init
c. you write your pact tests
d. run your tests
e. if they pass, Pact contract is found in the location defined (depends how you’ve defined it, but there’s a paragraph in README.md describing just that)
f. _ same as 1.h_
pact-consumer-swift
covers Pact Specification v2 (limited matchers):
https://github.com/DiUS/pact-consumer-swift
PactSwift
covers Pact Specification v3 (multiple matchers, handles example generators):
https://github.com/surpher/PactSwift