Most of the times during integration testing we have to run the built java code in server mode and run client junit/testng tests against the server. Mostly this has to be also done on the CI Jenkins server as well. Following post will go through some of the techniques to achieve the same.
Assuming the project is built in maven, run the integration test server (your application) in the pre-integration-test phase using maven-ant-run plugin.
Above maven plugin will run your main class in a forked jvm process in background and then you can run your junit/testNg integration tests against this server.
One of the issues that you will face is to stop the server once integration tests are complete.
For this you can create a method call to exit the test server if possible or exit the test server after a time interval. However this needs to be implemented server side. If you only run integration tests on Jenkins, Jenkins will make sure to kill all the pids that were created during a integration test run and keep integration test environment clean.
Happy testing...
Assuming the project is built in maven, run the integration test server (your application) in the pre-integration-test phase using maven-ant-run plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<version>1.8</version> | |
<executions> | |
<execution> | |
<id>start-test-server</id> | |
<phase>pre-integration-test</phase> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
<configuration> | |
<target> | |
<!-- To debug this forked process, set spawn=false only then stdout and stderr of process will be visible --> | |
<!-- Test will not run if spawn=false, but helps debug test server runs --> | |
<java spwan="true" fork="true" classname="your.example.com.MainClass"> | |
<jvmarg value="-Dproperties.file=file:/path/to/app.properties"/> | |
<classpath refid="maven.test.classpath"/> <!-- This basically means we will run current build --> | |
<env key="LD_LIBRARY_PATH" value="${yourNativeLibs}:${env:LD_LIBRARY_PATH}"/> | |
</java> | |
</target> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> |
Above maven plugin will run your main class in a forked jvm process in background and then you can run your junit/testNg integration tests against this server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project> | |
[...] | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-failsafe-plugin</artifactId> | |
<version>2.19.1</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>integration-test</goal> | |
<goal>verify</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
[...] | |
</project> |
One of the issues that you will face is to stop the server once integration tests are complete.
For this you can create a method call to exit the test server if possible or exit the test server after a time interval. However this needs to be implemented server side. If you only run integration tests on Jenkins, Jenkins will make sure to kill all the pids that were created during a integration test run and keep integration test environment clean.
Happy testing...