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.

Groovy consumer test does not report the real reason behind failure

See original GitHub issue

When running a consumer test and the closure passed into PactBuilder.run() throws an exception, the exception is caught and the test fails, but the real reason is not printed in the console.

The exception ends up in PactMismatch.userError, but PactMismatch.toString() does not print it out.

Example:

import au.com.dius.pact.consumer.PactVerified$
import au.com.dius.pact.consumer.VerificationResult
import au.com.dius.pact.consumer.groovy.PactBuilder
import org.junit.Test

class SwallowingUserErrorPactTest {

    @Test
    def void 'create a person'() {
        def myService = new PactBuilder()
        myService {
            serviceConsumer 'some consumer'
            hasPactWith 'some provider'
            uponReceiving 'a request to create a person'
            port 1234
            withAttributes(
                    method: 'post',
                    path: '/person',
            )
            willRespondWith(
                    status: 200
            )
        }
        VerificationResult result = myService.run() {
            throw new RuntimeException('this is not reported')
        }
        assert result == PactVerified$.MODULE$
    }
}

The output is

assert result == PactVerified$.MODULE$
       |      |                |
       |      false            Pact verified.
       Pact verification failed for the following reasons:

       The following requests were not received:
       Interaction: a request to create a person
...

but there is no mention of ‘this is not reported’

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lagershinscommented, Dec 8, 2016

@uglyog if the issue is that only a single exception can be thrown, wouldn’t it be possible to wrap all the root cause exceptions into a single exception and throw that? It could then print out the messages from all the root causes providing as much detail to the user as possible.

0reactions
uglyogcommented, May 4, 2017

For your test, the output is a little bit ugly, but it is all there:

Assertion failed: 

assert result == PactVerificationResult.Ok.INSTANCE
       |      |                            |
       |      false                        au.com.dius.pact.consumer.PactVerificationResult$Ok@2bf5dc88
       Error(error=java.lang.RuntimeException: this is not reported, mockServerState=ExpectedButNotReceived(expectedRequests=[	method: post
       	path: /person
       	query: [:]
       	headers: [:]
       	matchers: [:]
       	body: au.com.dius.pact.model.OptionalBody(MISSING, null)]))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Groovy consumer test does not report the real reason behind ...
When running a consumer test and the closure passed into PactBuilder.run() throws an exception, the exception is caught and the test fails, ...
Read more >
Error compiling the test file generated from spring cloud ...
I think your problem my come from a wrong declaration inside here: body([ "docId" : value(consumer('D1111'), producer(regex('.
Read more >
Why tests pass locally but fail in Jenkins | Object Partners
I've seen this occur when the test assertions are actually completed before the async calls finish. If possible, you should run your assertions ......
Read more >
Solved: Groovy Rerun Failed Test Case Execution Report
It is being addressed the issue incorrectly. First look for the reason why it is happening. If the services works with definitive behavior,...
Read more >
Writing Contract Tests with Pact in Spring Boot - kreuzwerker
The provider test fails because the consumer's contract is violated since it expects the name field. Provider changes date format. The provider ...
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