在 Maven 集成测试期间启动外部进程

我想要对 Maven 项目进行完全自动化的集成测试.集成测试要求在运行之前启动一个外部(平台相关)程序.理想情况下,外部程序会在单元测试完成后被终止,但这不是必需的.

I want completely automated integration testing for a Maven project. The integration tests require that an external (platform-dependent) program is started before running. Ideally, the external program would be killed after the unit tests are finished, but is not necessary.

是否有一个 Maven 插件来完成这个?其他想法?

Is there a Maven plugin to accomplish this? Other ideas?

推荐答案

你可以使用 antrun 插件.在里面你会使用 ant 的 exec 申请任务.

You could use the antrun plugin. Inside you would use ant's exec apply task.

类似的东西.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.2</version>
    <executions>
      <execution>
        <phase> <!-- a lifecycle phase --> </phase>
        <configuration>

          <tasks>
            <apply os="unix" executable="cmd">
              <arg value="/c"/>
              <arg value="ant.bat"/>
              <arg value="-p"/>
            </apply>
            <apply os="windows" executable="cmd.exe">
              <arg value="/c"/>
              <arg value="ant.bat"/>
              <arg value="-p"/>
            </apply>
          </tasks>

        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Ant 支持 os 特定命令当然是通过 条件任务.

相关文章