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” →
Scala provides nice and clean ways of dealing with Future objects, like Functional Composition and For Comprehensions. Future objects are a great way of writing concurrent and parallel programs, as they allow you to execute asynchronous code and to extract the result of it at some point in the future.
However, this type of software requires a different mindset in terms of reasoning about it, be it while writing the main code or while thinking about testing it. This article will focus primarily in testing this type of code and, for this, we’ll be looking into ScalaTest, one of the best and most popular testing frameworks in the Scala ecosystem (If you want to take a look at running integration tests with Docker/Docker-compose and Makefiles, take a look at this post).
Continue reading “Testing Future Objects with ScalaTest” →
I have recently published a course called “Build an application from scratch: JEE 7, Java 8 and Wildfly” on Udemy. This course is all about using a lot of recent and important Java technologies and best practices of software development in order to create a complete enterprise application. Some of the technologies and tools covered are:
- Java EE 7: JPA 2.1, Bean Validation 1.1, JMS 2.0, EJB 3.2, CDI 1.1, JAX-RS 2.0, security.
- Java 8: Lambda expressions, Date and Time API, streams and more.
- Libraries such as Gson, JUnit, Mockito and Hamcrest.
- Arquillian for integration tests.
- Wildfly 8 (former JBoss) as Application Server.
- PostgreSQL for production and HSQLDB/H2 for unit and integration tests.
- Eclipse IDE (this is a Maven project, so you can use other IDE).
- Postman Chrome extension to test all our REST endpoints.
If you are interested and want to know more details, you can check the course by clicking here. In this page, you can find more details about the course, watch some free videos.
If you have any questions, just let me know.
In this post we will see a brief introduction about the Spock test framework and how to integrate it with Maven and Eclipse.
Spock is a framework used to write tests using the Groovy language and its adoption has been increasing lately. Although Groovy is the language you must use to write your tests with Spcok, it can be used for both Groovy and Java applications and is compatible with most of the Java IDEs, including Eclipse.
The idea of writing the tests using Groovy can be seen as an obstacle for some Java developers that are not familiar with Groovy. However, the knowledge required in Groovy is quite basic and the Spock documentation itself is very helpful with this question. I myself, right now, know very little about Groovy and this hasn’t been an issue to write tests with Spock.
Continue reading “Integrating Spock with Maven/Eclipse” →
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” →