Software Develoment JourneyJava, Spring Framework, How-to

Integration tests with Maven 3, Failsafe and Cargo plugin

Unit testing is available in Maven out of the box. Because of that very often its used for integration tests as well. Major disadvantage of this is that integration tests can take much more time to execute and because no one likes to wait long time every build – tests are just skipped with -Dmaven.test.skip=true flag

In order to execute integration tests with Maven we should use Maven Failsafe plugin. Thanks to that we can quickly run unit tests by calling mvn test or perform integration tests with mvn verify.

Integration tests should run in environment similar as much as its possible to production. If your application is a WAR or EAR package you can use Maven Cargo plugin in order to tell Maven to deploy it on a application server or servlet container and perform integration tests on deployed application.

Maven Failsafe plugin configuration

In order to enable integration test phase failsafe plugin configuration has to be added to pom.xml

Of course integration tests should be more complex and actually test behavior. Right now you can setup Waitr, Selenium or any other solution that fits the best your needs and create real integration tests.

Conclusion

Do you always should test deployed application in integration tests? Its very useful but not always. If your application depends somehow on user’s ip address you will not be able to change it in different requests.

But if your application is a classic web app with HTML or REST frontend – then its highly recommended.