Manage Learn to apply best practices and optimize your operations.

Run code complexity tools and Java coverage tests with Maven

Maven integrates with various third-party software quality tools and can help developers with a number of tasks, including Java coverage tests and generating reports from code complexity tools. One of the easiest code complexity tools to configure with Maven is JaCoCo. A fundamental feature of JaCoCo is its ability to determine the McCabe cyclomatic complexity of a given function or method and then check if the unit tests successfully cover all of the cyclomatic routes. As the name implies, the JaCoCo code complexity tool evaluates and reports about Java code coverage.

JaCoCo code complexity tool
Figure 1. Java coverage report from the JaCoCo code complexity tool

How to install Maven

In this video, the first step is to install Maven and configure the M2_HOME and MAVEN_HOME system variables. After you complete the Maven install, issue a command to create a simple Java web application.

You can make minor edits to the Maven configuration file to complete the integration of JaCoCo. When the edit is complete, JaCoCo reports will be generated from the Java coverage tests.

Maven install complete
Figure 2. System variable configuration after the Maven install completes

Configure code complexity tools

The results generated from code complexity tools include more output and better graphs when they run against a slightly larger code base. The Maven example concludes with a look at a simple rock-paper-scissors application containing six source files and two unit tests. The JaCoCo report generated from this application demonstrates the type of insights modern code complexity tools can provide developers.

The takeaway from this Maven tutorial is just how easy it is to install the build tool, configure cyclomatic code complexity tools and run Java coverage tests. With Maven putting cyclomatic code complexity tools like JaCoCo at the fingertips of developers, there's no excuse to deliver software with anything less than 100% code coverage.

View All Videos
Cloud Computing
App Architecture
ITOperations
TheServerSide.com
SearchAWS
Close