pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

[pact-jvm-consumer-junit] Provide a way to shuffle generated values only once #503

Closed SchulteMarkus closed 10 months ago

SchulteMarkus commented 7 years ago

Hi there,

in my Pact, I am using (among others) "id" of type integer in the request body.

final DslPart body = new PactDslJsonBody()
  .integerType("id")

When doing my requests against the "Pact-server", "id" is shuffled on each request. In my test, I am having some subsequent HTTP-calls to my Pact-endpoint, where I expect the result to be constant (for that test). Is there a way to not shuffle "id" on each request?

uglyog commented 7 years ago

The shuffle you refer to is due to you not providing an example value, so a random one is generated each time. You can provide an actual value to use as the second parameter.

final DslPart body = new PactDslJsonBody()
  .integerType("id", 1000)
SchulteMarkus commented 7 years ago

In my case, it a little bit more complex. Let's say, I am expecting

[{"id":1}{"id":2}]

So, if I set "id" to "1000", both ids will have fixed value "1000", but I need different ones (which should stay constant between HTTP requests to the "Pact-server").

uglyog commented 7 years ago

Pact doesn't have any mechanism for keeping things constant between different requests, as this is starting to stray into behavioural testing space. Each request is validated in isolation.

We could look at using a sequence generator for IDs, but subsequent requests will get different IDs.

uglyog commented 7 years ago

Now that I think of it, by resetting the sequence for each request, you should then always get the same sequence of IDs

SchulteMarkus commented 7 years ago

Hmm, in my opinion, within the same JUnit-test, I would expect the Pact-server to answer the same response - just as I would expect it from another service.