Search code examples
javamaven-2build-processautomated-testsintegration-testing

Starting external process during integration testing in 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.

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


Solution

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

    Something like this.

    <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 support os specific commands of course through the condition task.