liveBook · Manning

Context keyword

As explained in Contract Testing in Action

A given statement declares the provider state or prerequisite that must exist before a Pact interaction is exercised.

A given statement declares the provider state that must exist before a Pact interaction runs. It turns a prerequisite into a named setup condition the provider can use to prepare test data. section 5.2

Movie API interaction

For a GET request to /movies, .given("a movie exists") tells the provider to create movie data before exercising the interaction. The statement is followed by the request description, path, and HTTP method. section 5.2

Figure 5.4 The Pact contract builder to be passed to the provider includes the given data upon receiving the HTTP request, URL path, and HTTP method.
figure

The interaction builder places the given data before the request description, URL path, and HTTP method. section 5.2

How Contract Testing in Action covers it

How deep it goes
Explains the declaration and its provider-triggered setup, but does not detail the underlying data-creation implementation.
Examples
Uses the condition “a movie exists” before requesting all movies from the /movies endpoint.
What you can do after
Builds a Pact interaction with a named provider prerequisite before defining its request and expected response.
How it connects
Connects provider state with Pact contracts, consumer tests, mock servers, HTTP requests, and provider verification.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.