Automating integration tests with docker-compose and Makefile

I remember a few years ago the adventure developers would face in order to run integration tests on their machines, as they had to install and configure external services (usually some RDBMS and application servers), use some shared testing environment, or something similar. Nowadays, docker has simplified a lot that situation, once external dependencies are available as images that can be used in any environment.

However, today it’s rather common to see applications that rely on many more external services than before, like different databases. Docker compose is another tool in the docker universe that helps applications to define all of their external dependencies, making much easier and cleaner to run (mainly) integration tests. But sometimes, only these tools are not enough. One still needs to start the containers, run some initialisation steps (like creating database, messaging topics, etc) and only then run their tests. For that, one can still rely on a quite old but popular tool: Makefiles.

In this article we’ll use a very simple application that has a repository class responsible for adding and retrieving entities in/from a MySql database. We also want to create a few integration test cases for this class using a real MySql server. The application is written in Scala and managed using SBT, but don’t get distracted by these details. The ideas shown here can be applied to any other programming language/building tool, as they are more related to the infrastructure than to the application itself.

Without further ado, let’s start!

Continue reading “Automating integration tests with docker-compose and Makefile”

Testing JEE6 applications with Arquillian

Creating automated tests for JEE applications has always been a challenge, once it requires a running container to provide all the services the application needs to work properly and that the tests need to be executed.

The Arquillian framework was born to make this job a lot easier to be executed. Your main goal is to provide a powerful test platform responsible of taking care of many aspects while testing JEE applications, such as start a container, deploy an application in the container, run the tests and stop the container. It also allows that your test classes can be enriched with annotations like @Inject, @EJB and @Resource, among others. This way, one can easily create real integration tests. Arquillian also allows users to choose either JUnit or TestNG to create and execute the tests, besides allowing the same test cases to be executed in different containers, such as JBoss, Glassfish and Tomcat.

This post’s goal is not to discuss the benefits in writing automated tests -TDD or not- but, instead, focus on how to use Arquillian through a practical example.

Continue reading “Testing JEE6 applications with Arquillian”