pact-jvm-provider-junit messaging tests fail when run via maven

Created on 26 Feb 2017  路  7Comments  路  Source: pact-foundation/pact-jvm

See this repo for an example: https://github.com/Fitzoh/pact-jvm-maven-test-issue

If you clone the project and run ProviderMessageTestthrough intellij, it will pass.

However, it run run the tests via maven (mvn test) it fails with the following message:

Verifying a pact between consumer and provider
  a test message
      Verification Failed - No annotated methods were found for interaction 'a test message'

Failures:

0) a test message
      No annotated methods were found for interaction 'a test message'

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.946 sec <<< FAILURE!
consumer - a test message(com.example.ProviderMessageTest)  Time elapsed: 0.327 sec  <<< FAILURE!
java.lang.AssertionError: 
0 - No annotated methods were found for interaction 'a test message'
        at au.com.dius.pact.provider.junit.target.BaseTarget.getAssertionError(BaseTarget.java:84)
        at au.com.dius.pact.provider.junit.target.AmqpTarget.testInteraction(AmqpTarget.java:51)
        at au.com.dius.pact.provider.junit.InteractionRunner$2.evaluate(InteractionRunner.java:181)
        at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.java:141)
        at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.java:101)
        at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.java:51)

Most helpful comment

I was able to run the test with the failsafe maven plugin, by adding the following config to the plugin:

 <configuration>
      <useManifestOnlyJar>false</useManifestOnlyJar>                                 
</configuration>

The test failed when being run with the failsafe (or surefire) maven plugins, because the SystemClassLoader returned only the failsafe/surefire booter.jar, when the classpath urls were being retrieved from it (check code in AmqpTarget.java ).

With the configuration in place, the full classpath is being listed through the SystemClassLoader, and therefore the @PactVerifyProvider annotations are correctly identified.

For more plugin configuration details, check Failsafe Class Loading

All 7 comments

This is a classpath issue when run from maven. I see if I can work out what is happening.

I'm hitting this very same issue. Works fine from IntelliJ but not through maven. It mentions "org.reflections.Reflections - Reflections took 6 ms to scan 1 urls, producing 0 keys and 0 values"
which seems wrong...

I think I found the issue. The failsafe runner was trying to run my producer tests, and since it at that point does not know about pact, it fails.

To work around it, I added my producer tests as excluded by failsafe, and I added the "pact-jvm-provider-maven" plugin to the "verify" lifecycle phase.

Now, failsafe will first run my consumer tests and then afterwards the "pact:verify" target will run to verify the producer.

Since I'm doing a proof-of-concept I have both producer and consumer in the same repo which creates this messy situation.

So for anyone running into this problem with producer tests, see if it's actually surefire (or similar) picking up and trying to run the tests, instead of the pact-maven plugin.

Any update on this issue. I'm facing the same issue.

@RaghuJ check that you are not running the verification as a test. It should be run by the pact-maven plugin and not a unit test.

@uglyog Thanks :) I was able to run it.

I was able to run the test with the failsafe maven plugin, by adding the following config to the plugin:

 <configuration>
      <useManifestOnlyJar>false</useManifestOnlyJar>                                 
</configuration>

The test failed when being run with the failsafe (or surefire) maven plugins, because the SystemClassLoader returned only the failsafe/surefire booter.jar, when the classpath urls were being retrieved from it (check code in AmqpTarget.java ).

With the configuration in place, the full classpath is being listed through the SystemClassLoader, and therefore the @PactVerifyProvider annotations are correctly identified.

For more plugin configuration details, check Failsafe Class Loading

Was this page helpful?
0 / 5 - 0 ratings