Skip to content

ppalaga/rpkgtests-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpkgtests-maven-plugin

This Maven plugin makes it possible to run tests from third party test jars outside their original source tree.

The problem

Say that a third party project publishes their test-jars on Maven Central and you want to run their tests as a part of your own build in a fully independent source tree.

You hope to make that possible by adding those test-jars as a dependency in the module where you want to run the included tests. But you will find our soon that Surefire/Failsafe Maven plugin cannot run those tests seamlessly. The build will most probably fail due to dependencies missing in the class path of the executed tests. Closer look will reveal that the missing dependencies are exactly the ones having the test scope in the POM of the test module of the third party project. This is caused by the fact that Maven, by design, does not (transitively) pull test dependencies for you - see https://issues.apache.org/jira/browse/MNG-1378

There are several solutions to this problem.

The "ban test scope" solution

Simply removing <scope>test</scope> from all dependencies on the side of the third party project would make your build work. It is rather unlikely that the third party project will be ready to do this for you.

The "split tests from the test app" solution

Another solution (on the third party project side) is to put the test classes into src/main/java directory of a separate Maven module. Good luck with asking the third party project to do this for you.

"Synthetic tests modules" solution

That’s what the rpkgtests-maven-plugin implements. All necessary steps happen on your side, so you’ll be able to run any third party tests without needing to do anything special on the third party side. The plugin downloads the test-jars (specified via the testJars mojo parameter) and the associated POMs and does the following modifications with them:

  • Renames the module by appending -rpkgtests to the original artifactId

  • Removes all non-test dependencies

  • Removes the test scope from every remaining dependency

  • Adds the dependency on the original artifact (without the -rpkgtests suffix)

The resulting pom.xml files are then installed along with the original test-jars into the local Maven repository. And your module in which you’d like to run them can seamlessly use them as test scoped dependencies.

Configuration

<plugin>
  <groupId>org.l2x6.rpkgtests</groupId>
  <artifactId>rpkgtests-maven-plugin</artifactId>
  <version><!-- Check the latest via http://central.maven.org/maven2/org/l2x6/rpkgtests/rpkgtests-maven-plugin/ --></version>
  <executions>
    <execution>
      <id>rpkgtests</id>
      <goals>
        <goal>rpkgtests</goal>
      </goals>
      <phase>generate-resources</phase>
      <configuration>
        <testJars>
          <testJar>
            <!-- The test-jar will be installed
                 along with the transformed POM as
                 org.my-org:my-artifact-rpkgtests:1.2.3
                 in the local Maven repository -->
            <groupId>org.my-org</groupId>
            <artifactId>my-artifact</artifactId>
            <version>1.2.3</version>
          </testJar>
        </testJars>
      </configuration>
    </execution>
  </executions>
</plugin>

Test Catalog XML

To provide a way how to easily rerun the desired tests, the maven-plugin implements goal create-test-jars-file. This goal creates an xml catalog containing all the groupId:artifacId pairs as configured within the project.

Configuration options

Static - the included groupId:artifactId pairs are read from the filesystem based on provided configuration as:

<execution>
  <id>create-test-jars</id>
  <inherited>false</inherited>
  <goals>
    <goal>create-test-jars-file</goal>
  </goals>
  <configuration>
    <testJarsPath>${project.basedir}/test-jars.xml</testJarsPath>
    <fileSets>
      <fileSet>
        <directory>${basedir}/..</directory>
        <includes>testable-*/pom.xml</includes>
      </fileSet>
    </fileSets>
  </configuration>
</execution>

Dynamic - the included groupId:artifactId pairs are dynamically collected from the maven reactor build, based on a predefined filtering property (if it’s set to true, the module is collected):

<execution>
  <id>create-test-jars</id>
  <inherited>false</inherited>
  <goals>
    <goal>create-test-jars-file</goal>
  </goals>
  <configuration>
    <testJarsPath>${project.build.directory}/test-jars.xml</testJarsPath>
    <activatingPropertyName>rpkgtests-activating-property</activatingPropertyName>
  </configuration>
</execution>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published