jenkins the definitive guide

(Jeff_L) #1
<groups>integration-tests</groups>·
</configuration>
</execution>
</executions>
</plugin>

¶ Do not run the integration-tests group during the test phase.
· Run only the tests in the integration-tests group during the integration-test phase.


It often makes good sense to run your tests in parallel where possible, as it can speed up your tests
significantly (see Section 6.9, “Help! My Tests Are Too Slow!”). Parallel tests are particularly intensive
with slow-running tests that use a lot of IO, disk or network access (such as web tests), which is
convenient, as these are precisely the sort of tests we usually want to speed up.


TestNG provides good support for parallel tests. For instance, using TestNG, you could configure your
test methods to run in parallel on ten concurrent threads like this:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>

As of JUnit 4.7, you can also run your JUnit tests in parallel using a similar configuration. In fact, the
configuration shown above will work for JUnit 4.7 onwards.


You can also set the configuration item to classes instead of methods, which will try to
run the test classes in parallel, rather than each method. This might be slower or faster, depending on the
number of test classes you have, but might be safer for some test cases not designed with concurrency
in mind.


Mileage will vary, so you should experiment with the numbers to get the best results.


A.2. Automating Your Tests with Ant


Setting up automated testing in Ant is also relatively easy, though it requires a bit more plumbing than
with Maven. In particular, Ant does not come packaged with the JUnit libraries or Ant tasks out of the
box, so you have to install them somewhere yourself. The most portable approach is to use a Dependency
Management tool such as Ivy, or to place the corresponding JAR files in a directory within your project
structure.


To run your tests in Ant, you call the task. A typical Jenkins-friendly configuration is shown
in this example:

Free download pdf