Maven-添加集成测试 [英] Maven - Add Integration Tests

查看:95
本文介绍了Maven-添加集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将Maven构建中的测试拆分为Unit&集成测试.

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

我正在使用故障安全插件来运行集成测试,并尝试使用build-helper-maven-plugin从src/it/java目录添加集成测试.

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>

堆栈跟踪:

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)

推荐答案

我配置了故障保护功能,以在其自己的目录中查找测试,并且工作正常!我还需要像您一样配置测试源目录.您需要配置构建助手插件以找到要编译的代码:

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>

这篇关于Maven-添加集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆