How do I run the integration tests?


In our project, we have a plenty of unit tests. They help to keep project rather well-tested.

Besides them, we have a set of tests which are unit tests but depends on some kind of external resource. We call them external tests. For example, they can sometimes access web-services.

While unit tests are easy to run, the integrational tests couldn't pass sometimes: for example, due to timeout error. Also, these tests can take too much time to run.

Currently, we keep integration/external unit tests just to run them when developing corresponding functionality.

For plain unit tests, we use TeamCity for continuous integration.

How do you run the integration unit tests and when do you run them?

In our project we have separate suite for regular/plain unit tests and separate suite for integration tests. The are two reasons for that:

  1. performance: integration tests are much slower,
  2. test fragility: integration tests fail more often due to environment-related conditions (give false positives).

We use TeamCity as our main Continuous Integration server and Maven as build system. We use the following algorithm to run the tests:

  1. We run unit tests at within Eclipse IDE and before every commit.
  2. We run unit tests automatically after each commit on TeamCity agents using Maven's mvn clean install
  3. We run integration tests automatically on TeamCity agent after "main" build is completed.

The way we trigger integration tests execution is by configuring TeamCity's integration.tests task to be dependent on "main" task, see here for details:

We run only integration tests (excluding unit tests) by:

  • using separate directory named "src/it/java" to keep integration tests,
  • excluding by default this source folder from maven-surefire-plugin configuration (configuration/excludes element),
  • using Maven profile called "integration" to exclude regular unit tests and include tests from "src/it/java" (this profile is configured by passing -Pintegration in integration.tests task).