Fork me on GitHub

Running a VM during integration tests

Here is a sample configuration demonstrating how to start/stop a virtual machine during integration-test phase:

<plugin>
  <groupId>net.ju-n.maven.plugins</groupId>
  <artifactId>vagrant-maven-plugin</artifactId>
  <version>1.0.2</version>
  <executions>

    <!-- Before tests: import box, start VM -->
    <execution>
      <id>setup-and-start-vagrant-vm</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>box-add</goal>
        <goal>up</goal>
      </goals>
      <configuration>
        <box>mytestbox</box>
        <url>${project.basedir}/src/test/resources/mytestbox.box</url>
      </configuration>
    </execution>

    <!-- After tests: shut down, destroy VM -->
    <execution>
      <id>destroy-vagrant-vm</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>destroy</goal>
      </goals>
    </execution>

  </executions>
</plugin>