首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven - Add集成测试

Maven - Add集成测试
EN

Stack Overflow用户
提问于 2017-10-19 22:13:16
回答 2查看 1.4K关注 0票数 3

尝试将Maven构建中的测试拆分为Unit & Integration测试。

我正在使用failsafe插件运行集成测试,并尝试使用build-helper-maven-plugin从src/it/java目录添加集成测试。

当我尝试进行构建时,我收到一个错误,我看不到原因,从模块的根文件夹到我的集成测试源的路径看起来是正确的。

代码语言:javascript
复制
[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]

任何想法都将非常受欢迎。谢谢

代码语言:javascript
复制
<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>

堆栈跟踪:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

发布于 2019-04-16 16:50:37

我将failsafe配置为在自己的目录中查找测试,它工作得很好!我还需要像您一样配置测试源目录。您需要配置build helper插件来查找要编译的代码:

代码语言:javascript
复制
<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>

以及用于运行该文件夹中的测试的故障保护插件:

代码语言:javascript
复制
<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>
票数 2
EN

Stack Overflow用户

发布于 2017-10-19 22:25:26

我不认为这是配置不同路径的正确位置。但是如果你想坚持使用这个build-helper-maven-plugin,你应该运行mvn -X并发布堆栈跟踪。

但我会尝试直接在maven-failsafe-plugin中配置不同的文件夹。请参见:

  • 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46831999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档