user656449
user656449

Reputation: 3032

Is it possible to have integration tests module built after main project

I have a maven project with integration tests module not included in main build by default, that is not listed in parent pom's list. The integration tests are usually being built after all other modules are ready. Integration tests also use resources (configuration files) located in other modules and refer to them by relative path (like ../common/src/main/..../config.xml). The question is if it is possible to do the same with jenkins, preferably, reusing workspace created by 'main' build?

Best regards, Eugene.

Upvotes: 2

Views: 2031

Answers (1)

khmarbaise
khmarbaise

Reputation: 97517

You can do both things which means either having the integrations tests in the same module but i recommend to have a separate module which contains the integration test parts.

If you have the module in your current module you need to setup it that way. If you have your integration tests in src/it/java

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
      <execution>
        <id>add-test-source</id>
        <phase>process-resources</phase>
        <goals>
          <goal>add-test-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>src/it/java</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

An other important thing is to use the maven-failsafe-plugin like this:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

But usually the best is to have a separate integration-test module which contains the stuff for the integration tests like the following structure:

   +-- root (pom.xml)
        +-- mod1 (pom.xml)
        +-- mod-it (pom.xml)
        +.. ..

The configuration in the mod-it is more or less the same as the previous example but you can avoid the buildhelper-plugin cause you would put your integration tests into src/test/java . It's important to be aware of the convention of the maven-failsafe-plugin which assumes to have IT's named like *IT.java etc.

Furthermore i can recommend to read this and the documentation here.

Upvotes: 4

Related Questions