Monday, July 19, 2010

Easy Maven integration tests

I'm working on a new IOC project mainly used for plugin discovery and management: mycila-plugin. I want to execute several integration tests using the artifact coming from my project, within other integration test projects since i need to test it in real projects with different dependencies. This IOC framwork automatically detects ASM and CGLIB in the classpath to use them to optimize injection and reflexion.

I came to a really simple solution. My project has the following structure:

it/noaop/pom.xml
it/noaop/src/test/java
it/withaop/pom.xml
it/withaop/src/test/java
src/main/java
pom.xml

In the root pom.xml I placed these plugins:

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <configuration>
        <filesets>
            <fileset>
                <directory>it/noaop/target</directory>
            </fileset>
            <fileset>
                <directory>it/withaop/target</directory>
            </fileset>
        </filesets>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-invoker-plugin</artifactId>
    <configuration>
        <projectsDirectory>it</projectsDirectory>
        <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
        <showErrors>true</showErrors>
        <streamLogs>true</streamLogs>
        <goals>
            <goal>test</goal>
        </goals>
        <pomIncludes>
            <pomInclude>**/pom.xml</pomInclude>
        </pomIncludes>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>install</goal>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Then when i run mvn integration-test, Maven executes the unit tests, packages, and then execute all the integration test projects with the newly installed dependency.

1 comment:

  1. Simply good, thanks for sharing information and putting up a good step by step tutorial man.

    ReplyDelete