kajman
kajman

Reputation: 1076

Run integration tests on CI server only using maven

Would it be wise to run unit tests every build but skip integration test phase entirely - leave it to CI server?

Currently I'm working on a JavaEE project which is covered almost only by some integration tests, which are poorly written and take a lot of time. Every time I make any change I have to wait few minutes for the build (from which like 90% of time are those integration tests).

My idea is to configure some CI server, for e.g. Jenkins, so that it would pick up any commit made to repository (or even better after a maven build) and run a maven build with integration tests. But is it possible to configure maven in a way that when I type mvn install it would compile-run unit tests-build the project, but omit the integration phase entirely (to speed up development). Then CI would pick up and start running the build again, but this time with integration-tests in place?

This way time between changing some code and deploying would be much shorter and less frustrating and any integration related bugs would be cached up in a matter of few minutes after CI server finishes the build.

Is this a good idea? Can anyone suggest how to configure maven to get such behaviour?

Upvotes: 3

Views: 1189

Answers (2)

Paul Dunnavant
Paul Dunnavant

Reputation: 616

You should be able to do this with profiles. Although I may need more information about the configuration of your integration tests. I've been doing this with projects for several years using a combination of the maven-failsafe-plugin and profiles. Here's an example snippet from a pom:

<profiles>
    <profile>
        <id>integration-tests</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>integration-test</id>
                            <goals>
                                <goal>integration-test</goal>
                            </goals>
                            <configuration>
                                ...
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

During normal local development, running mvn install shouldn't run integration tests that run via the maven-failsafe-plugin. Then, you can configure your CI server to run mvn clean install -Pintegration-tests.

Upvotes: 4

Lan
Lan

Reputation: 6660

First of all, I think it is a great idea. It will make your development cycle much faster.

I do not know a way to omit the integration-test phase completely when you execute mvn install. Can you execute "mvn clean package" instead during your development? If this is not an option, what plugin do you use for your integration test? Most plugin has an attribute "skip", which you can use to skip the execution of the plugin. You may want to use profile to turn the "skip" on and off for different scenarios.

Upvotes: 1

Related Questions