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.

How to implement customize output for pact?

See original GitHub issue

Hi Brother,

How to implement customize output for PactVerifierConfig , currently i use NUnit test framework in out project , and i want to output the pact test result in unit test window, but it didn’t work , can you give some demo code to handle it , thanks .

currently code as bellow:

`

        const string serviceUri = "http://localhost:51502";

        var config = new PactVerifierConfig
        {
            Outputters = new List<IOutput>
                              {
                                  new ConsoleOutput()
                              }
        };

        IPactVerifier pactVerifier = new PactVerifier(config);
        pactVerifier
            .ServiceProvider("Event API", serviceUri)
            .HonoursPactWith("Event API Consumer")
            .PactUri("userclient-userservice.json")
            .Verify();
    }`

ConsoleOutput implementation

public class ConsoleOutput: IOutput { public void WriteLine(string line) { Console.WriteLine(line); } }

when i run the test , it will throw the exception : PactNet.PactFailureException : Pact verification failed. See output for details. If the output is empty please provide a custom config.Outputters (IOutput) for your test framework, as we couldn't write to the console.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
neilcampbellcommented, Mar 20, 2018

Thanks for the detailed reply.

The ConsoleOutput is registered by default, and works for most test frameworks. xUnit however redirects the stdout and therefore the default handling does not work. See https://stackoverflow.com/questions/7138935/xunit-net-does-not-capture-console-output. When using xunit you need to provide a custom outputter, not the included ConsoleOutput. If you search the readme or samples for “XUnitOutput”, you can see an example of how this is done. That should hopefully get you the details about why the exception was actually thrown.

1reaction
neilcampbellcommented, Mar 19, 2018

@andreimcristof A PactFailure exception is thrown when something fails to be performed correctly, in Ken’s case the “Pact verification failed”. The “Note” part of that message is just saying that if you see no details about why the failure occurred, you may need to register a custom outputter. Not registering a custom outputter will never be the cause of an exception. The “Note” part is always written, regardless of test framework and if you have registered one or not, as we don’t know the runtime config at the time the exception is thrown. Does that make sense? Any suggestions to make this clearer?

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 minute guide | Pact Docs
1. Start with your model​ · 2. Create an Order API client​ · 3. Configure the mock Order API​ · 4. Write a...
Read more >
Implementing the provider changes - PactFlow Documentation
Implementing the provider changes · Go to your PactFlow account, find the new pact on the consumer branch feat/new-field and click "VIEW PACT"....
Read more >
pactFileWriteMode overwrite not working anymore in Pact
It is strongly recommended that this is set to false, as allowing modification makes the results of can-i-deploy unreliable.
Read more >
PACT Space Module Design Guide
4.2 PACT Space Module Core Design Strategies ... Patient-Centric Care Room/ Equipment and Supplies at Point-of-Use/ Diagnostic. Services ... This results in.
Read more >
VA extended PACT Act deadline today
The U.S. Department of Veterans Affairs extended the application deadline for veterans and survivors to apply or submit their “intent to file” ...
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