pact-foundation / pact-net

.NET 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://pact.io
MIT License
846 stars 232 forks source link

[Idea] Automatic record/replay mocks #67

Closed etiago closed 8 years ago

etiago commented 8 years ago

We recently started using pact-net at work and I'm slightly bothered by how much manual work is involved in creating the mocks and handling the resulting files.

I was thinking whether it would be a good idea (and whether someone thought about it) to create some sort of proxy generic mock which could be started in "record mode" and to which we would then direct our services. This proxy mock would (based on a config file) forward the requests to the actual service and then transport the response back to the actual service. This request/response interaction pair could then be saved as, e.g., a JSON file. Then, we would be able to start the proxy mock in a "replay mode" where it's simply replying to requests based on what it has recorded. This way we would avoid having to write the mock services ourselves and instead take the current snapshot of the provider as the "valid contract" upon which we base all our future test runs.

Has anyone thought about this? Do you see value on it if, e.g., I was to work on something along these lines?

neilcampbell commented 8 years ago

Hey @etiago Thanks for getting in touch, and I can appreciate there is a bit of work to get Pact up and running.

It is actually something we have chatted about and there are actually already tools which can do this should it fit your use case better [see https://github.com/vcr/vcr and https://github.com/matthew-cochran/Betamax.Net]. Pact kind of takes the reverse philosophy (see https://github.com/realestate-com-au/pact/wiki/FAQ#how-does-pact-differ-from-vcr).

With Pact the consumer defines only the fields it cares about in the req and res, nothing more, nothing less and as such that means service providers can validate the impact changes have on the consumers (given that all consumers use Pact and properly define the contracts), rather than assuming pretty much all changes are breaking changes.

etiago commented 8 years ago

@neilcampbell it makes sense, thanks for the pointers! Such a pity that Betamax.Net seems to be abandoned but I can understand that Pact-Net takes a different spin on it. :+1:

neilcampbell commented 8 years ago

@etiago I have a feeling other VCR ports for .NET exist, otherwise fork it and it's all yours :)