{"id":15481895,"url":"https://github.com/surpher/pactswiftpmexample","last_synced_at":"2025-03-28T14:32:23.617Z","repository":{"id":55607025,"uuid":"104472717","full_name":"surpher/PactSwiftPMExample","owner":"surpher","description":"An example project using pact-consumer-swift library using Swift Package Manager","archived":false,"fork":false,"pushed_at":"2021-05-12T22:10:53.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T05:19:24.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/surpher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-22T12:37:24.000Z","updated_at":"2021-09-22T20:38:39.000Z","dependencies_parsed_at":"2022-08-15T04:10:58.532Z","dependency_job_id":null,"html_url":"https://github.com/surpher/PactSwiftPMExample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpher%2FPactSwiftPMExample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpher%2FPactSwiftPMExample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpher%2FPactSwiftPMExample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surpher%2FPactSwiftPMExample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surpher","download_url":"https://codeload.github.com/surpher/PactSwiftPMExample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246046211,"owners_count":20714927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T05:06:51.221Z","updated_at":"2025-03-28T14:32:23.593Z","avatar_url":"https://github.com/surpher.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consumer Driven Contracts Testing using Swift Package Manager\n\n[![Build](https://github.com/surpher/PactSwiftPMExample/workflows/Build/badge.svg)](https://github.com/surpher/PactSwiftPMExample/actions?query=workflow%3ABuild)\n[![Swift Package Manager Compatible](https://img.shields.io/badge/swift_package_manager-compatible-brightgreen.svg)]()\n![Swift](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)\n[![Twitter](https://img.shields.io/badge/twitter-@pact__up-blue.svg?style=flat)](http://twitter.com/pact_up)\n\nThis project is an example of how to use [pact-consumer-swift](https://github.com/DiUS/pact-consumer-swift) framework.\n\n## Installation\n\n### Install the [pact-mock_service](https://github.com/pact-foundation/pact-ruby-standalone/releases)\n\nIn your terminal run:\n\n```bash\nbrew tap pact-foundation/pact-ruby-standalone\nbrew install pact-ruby-standalone\n```\n\n_This pact mock service will stand in for your API provider and run on localhost._\n\n## Running this demo project\n\n1. Clone the repo\n2. Sort out the dependencies\n3. Navigate to the root folder\n4. run `./scripts/build_test.sh` to run Pact tests\n5. run the app `.build/debug/PactConsumer` (the executable will call `https://swapi.co/api/people/1/` print the progress and eventually the result returned from the API)\n\n## Your Project\n\n##### Init your brand new executable Swift project\n\n`swift package init --type executable`\n\n#### Prepare your dependencies in `Package.swift` manifest file\n\nThis is an example from this project where Alamofire is used to make the network call:\n\n```swift\n// swift-tools-version:4.0\n\nimport PackageDescription\n\nlet package = Package(\n    name: \"PactSwiftPMExample\",\n    dependencies: [\n      .package(url: \"https://github.com/Alamofire/Alamofire.git\", from: \"4.8.2\"),\n      .package(url: \"https://github.com/DiUS/pact-consumer-swift\", from: \"0.6.0\")\n    ],\n    targets: [\n        // Targets are the basic building blocks of a package. A target can define a module or a test suite.\n        // Targets can depend on other targets in this package, and on products in packages which this package depends on.\n        .target(\n          name: \"PactConsumer\",\n          dependencies: [\"PactSwiftPMExample\"],\n          path: \"Sources/PactConsumer\"),\n        .target(\n          name: \"PactSwiftPMExample\",\n          dependencies: [\"Alamofire\"]),\n        .testTarget(\n          name: \"PactSwiftPMExampleTests\",\n          dependencies: [\"PactSwiftPMExample\", \"PactConsumerSwift\"]),\n    ]\n)\n```\n\nWrite your application...\n\n\n#### Overall Workflow Example\n1. `mkdir myProject \u0026\u0026 cd myProject`, `swift package init --type executable`\n2. Resolve dependencies by running `swift package resolve` in your project's root,\n3. Add your `Tests` and edit your `Sources`,\n4. Build the project by running `swift build`,\n5. Check if the app works by running `.build/debug/PactConsumer` (that's the target holding `main.swift` file) - by default it should print a response from [https://swapi.co/api/people/1/](),\n6. Start up the pact mock service by running `pact-mock-service start --pact-specification-version 2.0.0 --log \"./tmp/pact.log\" --pact-dir \"./tmp/pacts\" -p 1234`  \n(or if you're lazy just `pact-mock-service start`),\n7. Run your tests by running `swift test`,\n8. Stop the mock service by running `pact-mock_service stop`\n9. When your tests pass, you can find your pact contract file in `./tmp/pacts/_my-provider_-_my-consumer_.json` file  \n_(where provider and consumer is what we set it up in the PactTests_ `starWarsProvider = PactConsumerSwift.MockService(provider: \"_my-provider_\", consumer: \"_my-consumer_\")`_- if you were wondering...)_\n\n##### Notes\nFollowing best practices, you should write and run your unit tests before checking if the app works, do you agree?  \n\nTo avoid running 4 commands to start the mock service, build, test and shut down the mock service, there's a `scripts/build_test.sh` script in this repo that takes care of creating the `./tmp` folder, starting up the _pact-mock-service_, building the project, running the test, and then shutting down the service.  \nYou should probably set up your own test script/s based on your own requirements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurpher%2Fpactswiftpmexample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurpher%2Fpactswiftpmexample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurpher%2Fpactswiftpmexample/lists"}