3

trying to split my tests in a Maven build into Unit & Integration tests.

I am using the failsafe plugin to run the Integration Tests and attempting to use the build-helper-maven-plugin to add the Integration Tests from the src/it/java directory.

I am getting an error when I attempt to do the build and I can't see the reason, the path to my Integration Test source looks to be correct from the root folder of the module.

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source (add-test-resource) on project XXXX: The parameters 'sources' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source are missing or invalid -> [Help 1]

Any ideas will be more than welcome. Thanks

<plugin>
   <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals>
               <goal>add-test-source</goal>
            </goals>
            <configuration>
               <sources>
                  <source>src/it/java</source>
               </sources>
            </configuration>
        </execution>
        <execution>
           <id>add-test-resource</id>
           <phase>generate-test-sources</phase>
           <goals>
              <goal>add-test-source</goal>
           </goals>
           <configuration>
              <resources>
                <resource>
                  <directory>src/it/resources</directory>
                </resource>
              </resources>
           </configuration>
       </execution>
    </executions>
</plugin>

Stack Trace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source (add-test-resource) on project XXXX: The parameters 'sources' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source are missing or invalid
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
  at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
  at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
  at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
  at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
  at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'sources' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:add-test-source are missing or invalid
  at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:643)
  at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:596)
  at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
  at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
hexkid
  • 574
  • 1
  • 4
  • 13
  • 2
    Do not add a separate path for integration tests stick with src/test/java...only based on the naming schema...*IT.java is an integration test whereas *Test.java is a Unit test.... – khmarbaise Oct 19 '17 at 14:32
  • I'd prefer to explicitly separate the Unit Tests & the Integration Tests as they also rely on a separate set of test resource files. – hexkid Oct 19 '17 at 15:42
  • The resources files can be located in `src/test/resources` ? So where is the problem? – khmarbaise Oct 20 '17 at 07:59
  • The problem occurred due to a naming clash between the resources used for Unit & Integration Tests. We have resolved the issue and taken your approach but would still rather have kept the 2 test bases physically separate. – hexkid Oct 20 '17 at 15:28
  • If you really need to separate the classpath for testing the cleanest way is to create separate modules one which contains the integration tests part only... – khmarbaise Oct 20 '17 at 15:33
  • Can you try to merge the two executions? 1) The executions have the same id. 2) The stacktrace indicates that `sources` is a mandetory field. – asbachb Oct 23 '17 at 10:57

2 Answers2

3

I configured failsafe to find tests in its own directory and it works fine! I also needed to configure the test source directories as you did. You need to configure the build helper plugin to find the code to compile:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/integration-test/java</source>
                </sources>
            </configuration>
        </execution>
        <execution>
            <id>add-test-resource</id>
            <phase>generate-test-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/integration-test/resources</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

And the failsafe plugin to run the tests in that folder:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M3</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <testSourceDirectory>src/integration-test/java</testSourceDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
froderik
  • 4,642
  • 3
  • 33
  • 43
0

I dont think that this is the right place to configure the different paths. But if you want to stick with this build-helper-maven-plugin you should run mvn -X and post the stacktrace.

But I'd try to configure the different folders in maven-failsafe-plugin directly. See:

asbachb
  • 543
  • 3
  • 17