pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 480 forks source link

Pact tests not running with Maven Failsafe. #974

Open brettcooper opened 5 years ago

brettcooper commented 5 years ago

Hello, I am trying to separate out our Pact tests as integration tests that run with Maven Failsafe instead of running them as unit tests with Maven Surefire. The Pact tests run fine under Surefire, but when trying to run the same Pact tests with Failsafe, they are never run. I am not sure why Pact tests don't run with Failsafe? We are running Pact 4.0.2 with Junit 5. If you need more info, please let me know. Thanks for your help!

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
      <!-- This is for Pact. -->
      <useManifestOnlyJar>false</useManifestOnlyJar>
      <argLine>${argLine} -Xms1024m -Xmx6144m</argLine>
      <excludes>
        <exclude>%regex[.*(IntegrationTest).*]</exclude>
      </excludes>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.3.2</version>
      </dependency>
    </dependencies>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
      <includes>
        <include>%regex[.*(IntegrationTest).*]</include>
      </includes>
    </configuration>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
uglyog commented 5 years ago

From the failsafe documentation:

By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:

"/IT*.java" - includes all of its subdirectories and all Java filenames that start with "IT". "*/IT.java" - includes all of its subdirectories and all Java filenames that end with "IT". "/*ITCase.java" - includes all of its subdirectories and all Java filenames that end with "ITCase".

So either rename the test class to match one of those, or add an include on the failsafe configuration (you have an exclude in your example)

brettcooper commented 5 years ago

Whoops, think I had a copy / paste error. That should be an include for Failsafe, not an exclude. I updated my example above. We want to include tests that end in IT or IntegrationTest.