I want to start a server in pre-integration-phase and do some integration tests. Problem is that it only starts after the integration tests.
My pom looks like this:
plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<executableDependency>
<groupId>mygroup</groupId>
<artifactId>MyServer-Server</artifactId>
</executableDependency>
<mainClass>mygroup.myServer.MyServer</mainClass>
<arguments>
<argument>-batch</argument>
<argument>-port</argument>
<argument>1024</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
and my Test is a jUnit-Case named TestMyServerIT
located in src/test/main looks like this:
public class TestMyServerIT {
private Socket server;
@Test
public void testConnection() {
try {
server = new Socket("localhost", 1024);
} catch (IOException e) {
e.printStackTrace();
}
}
}
which fails with a connection denied if try mvn verify.
But it succeeds when I have a server running.
If I comment the test out, there is a server running on port 1024 after "mvn verify" since I don't stop it yet in the pom file. And I can access it on this port just fine, just not in time for the tests.
How can I assert the server is started before my tests?
It seems I have another problem I need to solve first. Failsafe-plugin is not starting on verify and says it is missing its xml if I try failsafe:verify