testing microservices in java hero image
December 11, 2019

Testing Microservices in Java

Java Testing
Microservices

Microservices are undoubtedly impacting the way in which applications are created today, as well as how we continue to manage our large existing applications. They provide unique opportunities for companies to create a more scalable version of their applications which can translate into highly performant applications. Due to the functional and operational complexities of microservices applications, testing microservices in Java applications is a point of emphasis for development teams.

In our article today, we’ll look at how Java applications have been tested historically, how that has changed with microservices adoption, and outline some of the major tenets of testing Java microservices.

A Short History of Java Application Testing

In the past, testing was often delegated to specific people who would focus on testing and releasing the application. It required testing massive applications with a large variety of complexities — making testing the application a convoluted and difficult process. More importantly, testing was difficult to scale — with a constantly changing group of engineers working on the project. When one person left the team or the company, the transition process was often painful and strenuous.

Vertical Organization of Development Teams

Often the break-up of those testing teams was done vertically so the application testing process wasn't likely to be understood by the developers, and vice versa. This resulted in people only knowing specific parts of the application. While there are some natural advantages to this approach, it also has some glaring weaknesses.

Take for instance a junior developer: They get incorporated into the development team in a position that doesn't pose much risk to the application. But, because they are only working on one part of the application, they are never developing with the larger scope of the application in mind. Not because they don't want to, but because they are not seeing the larger application and how it functions together. Because of this, they are less likely to understand how their code may negatively impact application functionality or performance.

That's especially true for microservices, where individual services can impact performance in other services — and in the combined application.

Testing Microservices in Java Applications

Due to the increasing adoption of microservices for a wide variety of Java applications, the need for robust testing has become more important than ever. Part of that is due to the increasing responsibilities for developers, but the more significant cause is that microservices applications can get complex quickly. That means that individual containers and the application both need to be continually tested to ensure success during microservices deployment.

One of the reasons that testing microservices is so difficult is because of the complications that come to play. Each service has its own built code base, database schema and dependency management. Because of these varieties, you often test the application locally by running up all these services and then running your testing options for your code.

Getting the services all up and running on your machine can take quite some time before you are able to test your application. This is often broken down into a couple of testing processes used in microservices: unit testing, load testing, end-to-end functionality testing, performance testing, and others.

Unit Testing Microservices in Java

When most think about testing an application of any kind, unit testing is the core of all software testing. The practice of unit testing has been tested and tried for years. Now when it comes to microservices, unit testing is critical to breaking down the application even further. By targeting small testable parts of the application, unit testing proves critical when identifying specific interactions your application is making.

Martin Fowler breaks unit testing up into two main categories:

  • Solitary unit testing - Unit testing is not done against real information stored in your database. This is typically done to run tests that won’t cause the entire application’s tests to fail.
  • Sociable unit testing - Unit testing is done against real information stored in your environment. Running unit tests this way often results in more issues appearing through the testing process than ideal in a local dev environment.

Load Testing Microservices in Java

Load testing is the process of running your full application in an environment as closely associated to your production environment as possible. This is something that must be run later in the testing process. It is typically focused on seeing how the application’s services work together.

Load testing is meant to be non-functional testing to best understand how your application works at normal and peak conditions. Understanding how many users can simultaneously use the application is critical to ascertaining the maximum operating capacity.

Automated Testing in Java Microservices

One of the biggest benefits for testing Java microservices is that many of the latest automation and testing technologies have versions developed specifically for microservices. In our recent article on Kubernetes vs Docker Swarm for container orchestration, we pointed out a free technology trio (Kubernetes, Istio, and Jenkins X) that can be used to create complex, automated, and disposable, testing programs that help applications to stably scale or release new features via canary release.

Once deployed, these test automation techniques are a veritable holy grail for developers who want to produce stable and scalable microservices applications. With this level of automation used for your microservices, you are going to be able to get a detailed grasp of your application. The problem that comes alongside this set-up is the set-up itself.

It is relatively easy to set up and maintain this automated testing process when you start your application with microservices in mind. But the reality in the microservices community is that the majority of these microservice applications are transitioned from large monolithic applications — making this automated testing process difficult to perfect. This results in most of these applications providing elements of automated testing but still requiring a plethora of other more manual testing practices within them.

End-to-End Functionality Testing Microservices in Java

In microservices, functionality goes beyond the functions performed by individual containers. Testing the overall functionality of the application, and developing the application in a way that makes it testable throughout its lifespan, is an important consideration for developers.

End-to-End functionality testing is focused on the customer’s direct experience with the application. Teams do not always go through this process before committing code to production but often things that aren’t caught through the more automated processes are identified during this process.

Performance Testing Microservices in Java

With DevOps changing how companies approach application testing, developers are increasingly responsible for the performance of their code as it applies to the entire application. But, with the emergence of microservices applications, performance issues can be harder to diagnose and fix. That’s especially true as microservices applications become more mature and, subsequently, more complex. So, how can developers get better performance during microservices application development?

XRebel for Microservices Performance Testing

XRebel is a must-have for developers working in Java microservices. It lets developers follow requests end-to-end in distributed applications and captures method-level performance data and IO events. That means a better understanding of how the application is functioning when developing individual containers, and the ability to avoid performance bottlenecks before they become an issue during production or scaling.

Most of these testing processes as shown are focused later in the testing process (automated testing or load testing) or production (performance testing). These means of addressing performance issues is results in extended periods of resolution due to having to step back in your application to address the issue or even identify the core reason for the issue. 

See How XRebel Can Help

Want to see XRebel in action?

Join us for a personalized demo! Click the link below to schedule a time.

See a Demo

Additional Resources

Looking for additional microservices resources? Our recent webinar, Improving Performance in Java Microservices, is a must-watch.

Articles

On-Demand Webinars