Reasons of separating and running only unit tests are:
- Need for running unit test before selenium tests - to simplify reasoning of failures.
- These kinds of tests require different settings in maven plugin configuration - parallel test running, ordering, system properties, JVM options, etc.
- Selenium tests are end-to-end and requires lot of configuration and deployment work, resetting application state (clearing database, starting and stopping of app server) - these works cannot be done easy on all development and staging environments
Maven have set of phases for separating steps of integration tests, also there are profiles which allow to gather selenium test configuration in single place.
Here is example of our end-to-end tests with selenium (unpack and run scripts to setup DB from scratch, start app server, run tests, stop app server, verify and report test results):
<profile>
<id>selenium</id>
<dependencies>
<dependency>
<groupId>com.thenewmotion</groupId>
<artifactId>msp-solveconnector</artifactId>
<version>${project.version}</version>
<classifier>sql-install</classifier>
<type>zip</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.thenewmotion</includeGroupIds>
<includeArtifactIds>msp-solveconnector</includeArtifactIds>
<includeClassifiers>sql-install</includeClassifiers>
<includeTypes>zip</includeTypes>
<includes>**/*.*</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.16</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>create-db</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost</url>
<username>${msp.db.user}</username>
<password>${msp.db.password}</password>
<orderFile>ascending</orderFile>
<fileset>
<basedir>${project.build.directory}/db</basedir>
<includes>
<include>1_drop_database.sql</include>
<include>2_create_database.sql</include>
<include>3_create_tables.sql</include>
<include>4_create_views.sql</include>
<include>5_create_foreign_keys.sql</include>
<include>6_data.sql</include>
</includes>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopKey>foo</stopKey>
<stopPort>8088</stopPort>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${msp.port}</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<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-failsafe-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemPropertyVariables>
<msp.user>${msp.user}</msp.user>
<msp.password>${msp.password}</msp.password>
<msp.baseUrl>${msp.baseUrl}</msp.baseUrl>
<webdriver.type>${webdriver.type}</webdriver.type>
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
</systemPropertyVariables>
<includes>
<include>**/*FT.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>