Maven - Add Integration Tests

家住魔仙堡 提交于 2019-12-07 13:09:59

问题


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)

回答1:


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:

  • http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#testSourceDirectory
  • http://maven.apache.org/components/surefire/maven-failsafe-plugin/examples/configuring-classpath.html



回答2:


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>


来源:https://stackoverflow.com/questions/46831999/maven-add-integration-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!