Pact verify not working - Annotated method not found during message provider test

3.3k views Asked by At

I have a project where we are using message provider since it involves Apache kafka based messaging.

Consumer side maven goals are working fine from local as well as from Jenkins.

Provider side pact-verify is failing in Jenkins saying "No Annotated method found for interaction".

My POM.xml config as below:

<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.11</artifactId>
<version>3.5.2</version>
<configuration>
    <!-- pactBrokerUrl,user name,password and project version required only 
                    for consumer -->
    <pactBrokerUrl>localhost</pactBrokerUrl>
    <projectVersion>0.0.1</projectVersion>
    <!-- service provider required only for producer -->
    <serviceProviders>
        <!-- <serviceProvider><name>provider</name><verificationType>ANNOTATED_METHOD</verificationType><consumers><consumer><name>consumer</name><pactUrl>pacturl</pactUrl></consumer></consumers></serviceProvider> -->
        <serviceProvider>
            <name>provider</name>
            <verificationType>ANNOTATED_METHOD</verificationType>
            <consumers>
                <consumer>
                    <name>consumer</name>
                    <pactUrl>pacturl</pactUrl>
                </consumer>
            </consumers>
        </serviceProvider>
    </serviceProviders>
    <classpathElements>
        <classpathElement>
          src/test/java
      </classpathElement>
    </classpathElements>
    <configuration>
        <pact.showStacktrace>true</pact.showStacktrace>
    </configuration>
</configuration>
</plugin>
2

There are 2 answers

0
sivaganesh sivakumar On BEST ANSWER

Resolved this issue. This is when we compile the project by skipping the test classes by using -Dskiptests. So right after this when we run the pact:verify the test classpaths are not included in the search.

Fixed it by compiling the test classes by using mvn test-compile compile and then running the pact:verify. Now the classes are getting picked up every single time.

3
Jose Martinez On

When doing producer side testing you need to provide the JSON contract. In those contracts you have the name of the producer. From your provider tests, you need to refer to the location of the contracts and the name of the provider.

@RunWith(RestPactRunner.class) // Custom pact runner, child of PactRunner which runs only REST tests
@Provider("myProducersNameAsItApearsInContract") // Set up name of tested provider
@PactFolder("path/to/pact/contracts") // Point where to find pacts (See also section Pacts source in documentation)

The name of the provider is in the contract as follows:

    "provider": {
    "name": "myProvider"
},

EDIT:

Problem here is the test is running fine and the annotated method is getting picked up when running from my local machine but when we are running from Jenkins that specific error is thrown during pact:verify.

You going to have to put the full pact folder relative to the Jenkins workspace for your project. Since we keep our pact contracts in src/test/resources/pacts then our @PactFolder value is as follows:

@PactFolder("src/test/resources/pacts")