Provider Contract Testing With Stubs in Nexus or Artifactory
Provider Contract Testing With Stubs in Nexus or Artifactory
It covers
topics such as flows of how to work with Spring Cloud Contract. We also cover some Spring
Cloud Contract best practices.
If you are starting out with Spring Cloud Contract, you should probably read the Getting
Started guide before diving into this section.
You can also check the workshop page for a step-by-step instruction on how to do this flow.
2.1. Prerequisites
Before testing provider contracts with stubs in git, you must provide a git repository that
contains all the stubs for each producer. For an example of such a project, see this
samples or this sample. As a result of pushing stubs there, the repository has the following
structure:
$ tree .
└── META-INF
└── folder.with.group.id.as.its.name
└── folder-with-artifact-id
└── folder-with-version
├── contractA.groovy
├── contractB.yml
└── contractC.groovy
You must also provide consumer code that has Spring Cloud Contract Stub Runner set up.
For an example of such a project, see this sample and search for
a BeerControllerGitTest test. You must also provide producer code that has Spring Cloud
Contract set up, together with a plugin. For an example of such a project, see this sample.
Annotation
JUnit 4 Rule
JUnit 5 Extension
@AutoConfigureStubRunner(
stubsMode = StubRunnerProperties.StubsMode.REMOTE,
repositoryRoot = "git://[email protected]:spring-cloud-samples/spring-cloud-
contract-nodejs-contracts-git.git",
ids = "com.example:artifact-id:0.0.1")
maven
gradle
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<!-- Base class mappings etc. -->
You can read more about setting up a git repository in the How To page of the
documentation.
See the workshop page for step-by-step instructions on how to do this flow.
4.1. Prerequisites
To use consumer-driven contracts with the contracts held in an external repository, you
need to set up a git repository that:
You also need consumer code that has Spring Cloud Contract Stub Runner set up. For an
example of such a project, see this sample. You also need producer code that has Spring
Cloud Contract set up, together with a plugin. For an example of such a project, see this
sample. The stub storage is Nexus or Artifactory
1. The consumer works with the contract definitions from the separate repository
2. Once the consumer’s work is done, a branch with working code is done on the
consumer side and a pull request is made to the separate repository that holds the
contract definitions.
3. The producer takes over the pull request to the separate repository with contract
definitions and installs the JAR with all contracts locally.
4. The producer generates tests from the locally stored JAR and writes the missing
implementation to make the tests pass.
5. Once the producer’s work is done, the pull request to the repository that holds the
contract definitions is merged.
6. After the CI tool builds the repository with the contract definitions and the JAR with
contract definitions gets uploaded to Nexus or Artifactory, the producer can merge its
branch.
7. Finally, the consumer can switch to working online to fetch stubs of the producer from
a remote location, and the branch can be merged to master.