Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dileep17/pact
spiking on PACT for contract testing
https://github.com/dileep17/pact
Last synced: 14 days ago
JSON representation
spiking on PACT for contract testing
- Host: GitHub
- URL: https://github.com/dileep17/pact
- Owner: Dileep17
- License: mit
- Created: 2021-02-09T09:53:09.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-06-30T12:53:47.000Z (over 1 year ago)
- Last Synced: 2024-11-05T10:59:51.951Z (2 months ago)
- Language: Java
- Size: 232 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Repo set for spiking on PACT with java 8, springboot and Junit5
Picked below from [PACT](https://docs.pact.io/)
Contract testing is a technique for testing an integration point by checking each application in isolation to ensure the messages it sends or receives conform to a shared understanding that is documented in a "contract".
Pact is a code-first tool for testing HTTP and message integrations using contract tests.
### Pact broker
Run `$docker-compose up` to bring up pact broker. This should be done before running pact consumer & producer tests.
Access pact ui @ http://localhost:9292/
credentials are hardcoded in docker-compose file: webadmin/password@312### Consumer :- order service
Has following endpoints
1. /getOrder -> fetches product information from productservice for product with id 1 & 2 (hardcoded) and returns orderConsumer contract tests are in ProductServiceContractTest.
To run tests run following command in productservice folder
$ mvn clean test
This will generate pact contract files @ /orderservice/target/pacts/*.json
To push pact contracts to Pact Broker use below. Make sure pact broker is up before publishing.
$ mvn pact:publish -Dpact.consumer.tags=test
tags can be changed based on need. Pact broker url and credentials are configured on pom.xml @ au.com.dius.pact.provider:maven plugin
To start service
$ mvn spring-boot:run
### Producer :- product service
Has following endpoints
1. /product/new -> used to setup data
2. /product/search/name/{name} -> returns list of products with matching name
3. /product/search/id/{id} -> returns product with idProductServiceApplication creates two products at boot time.
ContractTest class contains producer contract tests (auto generated by TestTemplate based on pact files). Pact files are downloaded from pact broker. Pact broker information such as url, credentials etc are set as attributes on ContractTest class.
To run tests run following command in productservice folder
$ mvn clean test
If pact files are not picked from pact broker, copy the pact files generated by consumer contract tests (orderservice and web) into productservice/pacts folder manually. @PactFolder on ContractTest class maps the location of pact contract files.
To start service
$ mvn spring-boot:run
### Consumer :- web
This is a simple React project which depends on product service. user can search for product by name in UI and matching products will be displayed
Run `npm start` in web folder to start UI
Run `npm run contracttests` to run contract tests. Pact contract files will be generated in /web/pacts/*.json
### Todo* pact mock multiple producers in a contract test
* auto update consumer contract versions and producer to run tests against a specific version
* update pack broker with test results (pass/fail examples)
* check out https://docs.pact.io/pact_broker/can_i_deploy/