Posts Tagged ‘integration tests’

Integration Testing, Maven, and GAE

September 8, 2013

I’m starting to use REST-assured for integration testing my REST APIs.  It provides a nice clean way of writing integration tests and, of course, I’d like them to be run automatically.

Maven Integration Tests

While unit testing is pretty much ready to go out of the box in Maven, integration testing isn’t.  It is not too hard but there’s a couple of things that need to be done. First, you have to pull Fail Safe into Maven with:
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>${maven.failsafe.version}</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Now, when you execute the maven verify goal, test classes of the pattern IT*.java or *IT.java are automatically executed. This works well until you realize that real integration tests require a bit more setup than unit tests do.
 

GAE Dev Server and Integration Testing

In particular, I want the GAE dev server running before the integration tests run.  So all we should have to do is get the GAE plug-in to execute the devserver_start goal during pre-integration-test and the devserver_stop goal to execute during post-integration-test.
<plugin>
  <groupId>com.google.appengine</groupId>
  <artifactId>appengine-maven-plugin</artifactId>
  <version>${appengine.target.version}</version>
  <executions>
    <execution>
      <id>start-gae</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>devserver_start</goal>
      </goals>
    </execution>
    <execution>
      <id>stop-gae</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>devserver_stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Now, executing mvn verify will run your integration tests once your unit tests pass and the GAE dev server should start and stop around the integration tests as well.
Advertisements