开发者

Running tests after packaging

One of my projects needs a pretty complex setup for the resulting JAR file, so I'd like to run a test afte开发者_运维技巧r the package phase to make sure the JAR contains what it should.

How do I do that with Maven 2?


You can use the surefire-plugin for this. what you need to do is associate a phase with an execution (see below). You will need to change the phase to be whatever you want it to be in your case one after the package phase.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>unittests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <includes>
                            <include>**/**/**/*Test.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>


Convert your project into a multi-module build. In the first module, build your original project. In the second module, add a dependency to the first.

This will add the first JAR to the classpath.


Update by OP: This works but I had to add this to my POM:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${version.maven-surefire-plugin}</version>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>

The important part is <useSystemClassLoader>false</useSystemClassLoader>. Without this, my classpath only contained a couple of VM JARs plus the surefire bootstrap JAR (which contains the test classpath in the MANIFEST.MF). I have no idea why this test classpath isn't visible from the classes loaded from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜