Skip to content

Example generators

Marko Justinek edited this page Sep 18, 2020 · 11 revisions

The example requests and response bodies stored in a pact file are static. The idea being that the pact file represents a contract that can always be fulfilled if the provider is in the correct state. However, this assumption is not always correct. In some cases, dates and times may need to be relative to the current date and time, and some things like tokens may have a very short life span.

An example of the date issue is a provider which only accepts a date value in the current financial year. As soon as we switch over to a new financial year (or any time period), that pact file can no longer be used.

PactSwift provides the following example generators:

RandomInt(min:max:)

Generates a random integer value between provided min and max values

// DSL
ExampleGenerator.RandomInt(min: Int, max: Int)
Clone this wiki locally