Individual verification of interactions
See original GitHub issuePactVerifier.Verify() verifies all interactions in one go. For any non-trivial pact, this is not ideal:
- If there are 100 (independent) interactions and only one of them fails, the test (running in Visual Studio or TeamCity) as a whole will be marked as failing.
- All the verifier output goes into a single window that’s difficult to scan for the information you need (about a particular failure, say). If you run the test in ReSharper, the output will likely be truncated (““The output has reached the limit and was truncated. To view the full output use ‘Show Stack Trace in a new window’ action.””), and you have to change ReSharper settings to see all of it.
It would be great if PactVerifier provided an interface to get at the individual interactions and validate them separately. This could be used to drive an xUnit MemberData-based test, for example.
Is this something that would be feasible to support in the current protocol with pact-provider-verifier? E.g., can the verifier return some structured (json) representation of the verification results? The PactProvider would capture these results in a separate step, and defer the actual verification. IPactVerifier could expose the interactions via GetInteractions(), perhaps.
Could I write a custom outputter to achieve something like this? I think it should be exposed a high-level api, if possible.
public interface IInteraction
{
void Verify();
}
public static IEnumerable<object[]> GetInteractions()
{
// ... initialize the service as usual ...
var pactVerifier = new PactVerifier(config);
return pactVerifier
.ProviderState($"{serviceUri}/provider-states")
.ServiceProvider(providerName, serviceUri)
.HonoursPactWith(consumerName)
.PactUri(absolutePactFilepath)
.GetInteractions();
}
}
[Theory]
[MemberData(nameof(GetInteractions))]
public void VerifyInteraction(IInteraction interaction)
{
interaction.Verify();
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:19 (11 by maintainers)
Top GitHub Comments
@bethesque Could you advise on how to hardcode json format in pact_spec_runner? I’d like to examine the output for our existing pacts to decide whether introducing this option is the way to go.
Both stdout and stderr are routed to IOutput.WriteLine(string line): https://github.com/SEEK-Jobs/pact-net/blob/master/PactNet/Core/PactCoreHost.cs#L108 The IOutput interface would have to be changed to let outputter implementations handle them separately.
Closing this one as it’s now almost 5 years old 😁
From the original question, it’s not possible currently to auto-generate a test case per interaction in xUnit or other popular frameworks due to how the internals of pact work.
Previously it wrapped a Ruby core library and now it’s rewritten in Rust, which centralises all the verification logic in a place where PactNet can’t get at it. That makes things like auto-generating test cases in a client library infeasible unfortunately.