question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Individual verification of interactions

See original GitHub issue

PactVerifier.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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
khansencommented, Oct 23, 2017

@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.

0reactions
adamrodgercommented, May 27, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito - verifyNoMoreInteractions- multiple calls with ...
Automatic verification of individual calls to verify() can be enabled ... myTest(SomeServiceTest.java:30) But found this interaction on mock ...
Read more >
Mockito Verify Cookbook
Mockito Verify examples, usage and best practices. ... Verify no interaction with the whole mock occurred:
Read more >
Interaction Based Testing
Interaction -based testing is a design and testing technique that emerged in the Extreme Programming (XP) community in the early 2000's.
Read more >
verifyNoMoreInteractions() and verifyNoInteractions()
Checks if any of given mocks has any unverified interaction. We can use this method after calling verify() methods. It is to make...
Read more >
Mockito 3.4.2 API - javadoc.io
Verification in order is flexible - you don't have to verify all interactions one-by-one but only those that you are interested in testing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found