0

I want to run junit tests, while jetty is running , how to correctly configure this? Now it seems that the tests run before jetty is started so they can't get a connection and the project build fails.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.7.1</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
                <execution>
                    <id>verify</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.10.v20130312</version>
            <configuration>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
                        <port>9090</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopKey>foo</stopKey>
                <stopPort>9999</stopPort>
                <jvmArgs>-Xms1024m -Xmx2048m</jvmArgs>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit4</artifactId>
                    <version>2.16</version>
                </dependency>
            </dependencies>
        </plugin>

Please help me with this! How to ensure that the junit tests (during the maven build) run in the integration-phase?

April
  • 435
  • 1
  • 5
  • 9

1 Answers1

0

The Maven test phase is for running 'Unit' tests, that is, small tests that check that the smallest possible functionality or 'Unit' is functioning as expected.

These are run by the Maven Surefire plugin. You can find more info on this here: http://maven.apache.org/surefire/maven-surefire-plugin/

What you have are integration tests. That is, they are broader tests that check that different parts of your code integrates together. This is run by the Maven Failsafe plugin which you can find more details on here: http://maven.apache.org/surefire/maven-failsafe-plugin/

What you need to do is identify your integration tests as integration tests to the Failsafe plugin. By default, it picks up classes named **/IT*.java, **/*IT.java, and **/*ITCase.java. The naming conventions between the plugins is mutually exclusive by default so your tests should only run in one or the other.

If you only have integration tests then you can configure Surefire to run during the integration-test phase instead. Instructions on doing that here: http://docs.codehaus.org/pages/viewpage.action?pageId=62120

Mardoz
  • 1,617
  • 1
  • 13
  • 26
  • yes, but if I want the junit tests to run also during the integration-phase, is it possible ? – April Apr 10 '14 at 13:39
  • Why would you want the same tests to run in multiple phases? The solution in paragraph 4 is the proper way you should be following. – Mardoz Apr 10 '14 at 13:47