Comparison: Code Analysis Tools
Tags: dvops, testing, code, coverage
Published: 2021-02-09 16:55:47

Code analysis tools are essential to gain an overview and understanding of the quality of your code. This post is going to cover the following
<ol>
 	<li aria-level="1"><a href="https://about.codecov.io/">Codecov</a>;</li>
 	<li aria-level="1"><a href="https://coveralls.io/">Coveralls</a>;</li>
 	<li aria-level="1">And <a href="https://www.codacy.com">Codacy</a>;</li>
</ol>
While these tools target similar use cases, they differ in their implementation, ease of use, and documentation just to name a few.

<a href="https://codefresh.io/wp-content/uploads/2021/02/image3.png"><img class="wp-image-18768 size-medium" src="https://codefresh.io/wp-content/uploads/2021/02/image3-300x114.png" alt="code-coverage-comparison" width="300" height="114" /></a>

This post provides an overview of each tool as well as a detailed comparison to help analyse and decide which tool is best suited for your needs.
<h3><b>Overview</b></h3>
Code analysis tools make it possible to access, group, and merge analysis reports of your application. Test coverage reports used in combination with code analysis tools provide comprehensive insights on the quality of your code.

This allows developers to know their code quality today and improve it tomorrow. Specifically, to
<ul>
 	<li aria-level="1">Improve poorly written code;</li>
 	<li aria-level="1">Develop robust and secure applications;</li>
 	<li aria-level="1">Receive insights into the code quality over time;</li>
 	<li aria-level="1">Ensure test coverage is done throughout the codebase.</li>
</ul>
In the best case, you would want to have all the insights on your code quality in one place. This is made possible by Codacy, Codecov, and Coveralls.

The next sections will compare distinct aspects of each tool with its competitors. We tried all 3 tools with our own project in order to gain a better understanding of how they work. Here is each blog post if you want to see what we did:
<ul>
 	<li aria-level="1"><a href="https://codefresh.io/howtos/code-coverage-codecov/">Codecov</a></li>
 	<li aria-level="1"><a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls</a></li>
 	<li aria-level="1"><a href="https://codefresh.io/howtos/codacy-coverage-reports/">Codacy</a></li>
</ul>
&nbsp;
<h3><b>Features</b></h3>
Now that we discovered that all three tools have the same goals in mind, let’s take a look at the features each tool pursues and the ways they differ.

<b>Each tool has been evaluated based on the following criteria</b>
<table>
<tbody>
<tr>
<td><b>Feature</b></td>
<td><b>Description</b></td>
<td><b>Clear Difference</b></td>
</tr>
<tr>
<td><b>Pricing</b></td>
<td>The flexibility of the pricing options
and the extent to which those are justified</td>
<td>Coveralls is the only tool of the three that
charges per repository rather than per user</td>
</tr>
<tr>
<td><b>Ease of Use</b></td>
<td>Whether or not it was intuitive
to get started with the tool</td>
<td>Coveralls was the easiest to
integrate within our project</td>
</tr>
<tr>
<td><b>Documentation</b></td>
<td>The quality of the overall documentation,
whether examples were provided,
integration with CI/CD providers,
and the clarity of the conveyed information</td>
<td>Codecov had the most comprehensive documentation
that left little to no room for ambiguity,
making it easy set-up and expand the integration with our project</td>
</tr>
<tr>
<td><b>Dashboard</b></td>
<td>The functionality of the Dashboard
and the way information is displayed.</td>
<td>While the Codacy Dashboard is not the easiest to navigate,
it did provide the best data visualisation</td>
</tr>
<tr>
<td><b>Historical Data</b></td>
<td>Whether it is possible to access historical data,
view trends, and analyse code changes</td>
<td>All tools enable this feature in a different format</td>
</tr>
<tr>
<td><b>CI/CD Integration</b></td>
<td>Ease of automating the process of creating code
coverage reports and forwarding those to a CI platform</td>
<td>Codecov did not require extensive custom set-up
to integrate with Codefresh</td>
</tr>
</tbody>
</table>
<h3><b>Pricing</b></h3>
Both Codacy and Codecov provide a free version, a pro-version and an on-premises version. In the case of Codecov, all pricing options are <a href="https://about.codecov.io/pricing/">detailed on their website.</a> In comparison, <a href="https://www.codacy.com/pricing">Codacy does not clearly state</a> the service provided with the free version. Additionally, both platforms charge per user, who receives access to an organization’s repository.

Coveralls, on the other hand, has more <a href="https://coveralls.io/pricing">segmented pricing options</a> with 5 different tiers. Additionally, it provides free analysis for open source. The remaining options are priced depending on the number of repositories that receive coverage reports rather than the number of users, who need access to the platform.

Given the information provided by each tool, we would recommend startups and open-source projects to go with Coveralls. While they currently do not provide extensive support to projects, they clearly state their belief in the open-source ethos and provide a flexible pricing model. Additionally, paying Coveralls per repository provides more predictable pricing. Depending on the size of your team and the number of repositories that have to be covered, Codecov will provide the best option for its price. However, if your company would like to receive additional features, it might be worth looking into the enterprise and on-premises solutions provided by Codecov and Codacy since both provide a few more features than Codecov.
<h3><b>Reports and Analysis</b></h3>
All three platforms provide a comprehensive dashboard through which code analysis reports can be accessed. This section will look at the features of each platform before providing a comparison. Note that we uploaded to each platform the same coverage report.

The coverage reports uploaded to each platform were based on a<a href="https://github.com/codefresh-contrib/coveralls-sample-app"> Typescript application</a>. Thus, reports had to be in either of the following formats: json, xml, or txt.

Both <a href="https://docs.codecov.io/docs/supported-languages">Codecov</a> and <a href="https://docs.coveralls.io/">Coveralls</a> suggest different testing and coverage report frameworks depending on the language used throughout a comprehensive list of examples. In comparison, Codacy provides <a href="https://docs.codacy.com/coverage-reporter/generating-coverage-reports/">a list of suggestions</a> that are not directly managed by Codacy. This makes it a bit more difficult to understand the potential and implementation of Codacy. Once we have uploaded our coverage report, we can view the information in the respective Dashboards.
<h3><b>Codecov</b></h3>
<a href="https://codefresh.io/wp-content/uploads/2021/02/image1-1.png"><img class="size-medium wp-image-18769" src="https://codefresh.io/wp-content/uploads/2021/02/image1-1-276x300.png" alt="Codecov" width="276" height="300" /></a>

The Codecov Dashboard is divided into several sections with a top menu bar. Each coverage report is classified in either of the following categories:
<ul>
 	<li aria-level="1"><b>hit</b> indicates that the source code was executed by the test suite.</li>
 	<li aria-level="1"><b>partial</b> indicates that the source code was not fully executed by the test suite; there are remaining branches that were not executed.</li>
 	<li aria-level="1"><b>miss</b> indicates that the source code was not executed by the test suite.</li>
</ul>
This is visible in the files section of the Dashboard in the form of a street-light system.
<h3><b>Coveralls</b></h3>
<a href="https://codefresh.io/wp-content/uploads/2021/02/image4.png"><img class="size-medium wp-image-18770" src="https://codefresh.io/wp-content/uploads/2021/02/image4-294x300.png" alt="Coveralls" width="294" height="300" /></a>

Coveralls follows a unique style throughout its platform. Similar to Codecov, Coveralls uses the percentage of the project covered by tests to analyze its code quality. Furthermore, with every new code coverage upload, Coveralls makes a separate entry into the recent builds section of the Dashboard. This entry includes the coverage percentage of the repository. While a graph for enhanced visualisation of code coverage improvements would be nice, it is not necessary to understand the coverage change over time.
<h3><b>Codacy</b></h3>
<a href="https://codefresh.io/wp-content/uploads/2021/02/image8.png"><img class="size-medium wp-image-18771" src="https://codefresh.io/wp-content/uploads/2021/02/image8-300x146.png" alt="Codacy" width="300" height="146" /></a>

Similar to Codecov, Codacy focuses on enhancing its code analysis by connecting coverage reports with the information recorded on your git repository. This includes issues, pull requests and commits. From the main Dashboard, users can access specific information on the repository, such as file coverage. However, Codacy does not provide you with an option to view coverage reports directly. The pro version allows users to set-up security alerts, which is a feature that is unique to Codacy.

Separately, Codacy provides additional tools such as user management, separate configuration for file support, and setting quality standards.
<h4><b>Comparison</b></h4>
<ul>
 	<li aria-level="1">Coveralls was the most intuitive platform of the three. However, this can be considered a positive side-effect of Coveralls focusing on the core features needed to create curated coverage reports rather than providing too many options that might confuse users.</li>
 	<li aria-level="1">In contrast, both Codecov and Codacy place more focus on the visualisation of the coverage reports that enhance the Dashboard.</li>
 	<li aria-level="1">An additional feature worth highlighting is the option to compare branches directly within the Codecov UI.</li>
 	<li aria-level="1">In the case of Codacy, the complex UI used to accommodate all features was a problem. The Codacy UI has two settings taps with similar features. When setting up the integration, it was not clear which API token should be used. More on this in the integration section.</li>
 	<li aria-level="1">Overall, there is not much to set-up or to customise within the UI, which results in a similar workflow while using each tool.</li>
</ul>
<h3><b>Historical Trends</b></h3>
Historical Trends are necessary to reason between events, changes done to the code base and the results of the code coverage. Depending on the way historical trends are displayed, it becomes easier for developers to identify good practices that led to higher code quality.

All platforms provide historical trends. While Codacy provides the best visualisation of reports over time as an average, it makes it difficult to access coverage reports directly from within the tool. Looking at Codecov and Coveralls, also the simplified Dashboards makes it possible to reason about changes in code coverage within respective files and repositories.

Summarising, the information provided by Codacy is better when looked at high-level but does not provide an advantage when users want to analyse specific files.
<h3><b>Code Analysis</b></h3>
Using a code coverage solution makes it possible for users to access additional information on the quality of their code. The following screenshots showcase the analysis interface of the file that we ran tests on. It is worth highlighting that Codacy analyses the code quality of all files within the git repository by default. Resulting, also files that are not part of the code coverage report are automatically analysed.

<b>Codecov</b>

<a href="https://codefresh.io/wp-content/uploads/2021/02/image6.png"><img class="size-medium wp-image-18772" src="https://codefresh.io/wp-content/uploads/2021/02/image6-300x125.png" alt="codecov-code-analysis" width="300" height="125" /></a>

<b>Coveralls</b>

<a href="https://codefresh.io/wp-content/uploads/2021/02/image7.png"><img class="size-medium wp-image-18773" src="https://codefresh.io/wp-content/uploads/2021/02/image7-300x157.png" alt="Coveralls Code Analysis" width="300" height="157" /></a>

<b>Codacy</b>

Note that Codacy has some additional logic that did not allow us to access the js file created from the ts file. Thus, we used the ts file instead to analyse our code quality.

<a href="https://codefresh.io/wp-content/uploads/2021/02/image2.png"><img class="size-medium wp-image-18774" src="https://codefresh.io/wp-content/uploads/2021/02/image2-300x149.png" alt="Codacy Code Analysis" width="300" height="149" /></a>

In this category, Codacy clearly provided the most information on each line of code, highlighting the improvements that can be made. However, by doing so, the platform enforces specific practices onto your codebase. For instance, in the case of JavaScript, there is no need to provide semicolons but their tool will flag those as missing and downgrade the code quality. By not flagging distinct coding styles, Codacy could be used to enforce a coding style within the organisation.
<h3><b>Documentation </b></h3>
Your need for good documentation will vary, depending on the way you want to use the tools and access code coverage reports. Sadly, the documentation is often that part of a product that is least taken care of. Good documentation allows users to get started quickly, avoid ambiguity, and optimise the use of the platform over time.

When comparing the documentation by Codecov, Coveralls and Codacy, the following became apparent
<ul>
 	<li aria-level="1">Codecov has the most comprehensive documentation since it covers every aspect of the product with great detail.</li>
 	<li aria-level="1">Coveralls’ documentation was the easiest to navigate given that it focuses on the essential operations that users would want to do.</li>
 	<li aria-level="1">Both Codecov and Coveralls provide a comprehensive list of examples that users can choose from depending on the programming language and framework used in their application. This was greatly missed within Codacy, which is further detailed in the next section.</li>
</ul>
<h3><b>Use and Ease of Implementation</b></h3>
The use and ease of implementation is arguably the most important aspect of each platform. Depending on the tool that is added to your existing workflow, you do not want to change your entire processes to accommodate one tool. Thus, it is necessary for code coverage and analysis tools to understand at what point coverage reports are created in the development lifecycle. This will allow the tool to provide seamless integration into the testing and coverage process that a team has already established.

Using Codefresh to connect our code coverage reports to the respective tool makes it possible to automate the process of running tests, creating coverage reports, and uploading those to the code analysis tool. This section will detail our experience integrating each analysis tool within our Codefresh pipeline.
<h3><b>Integrate with each tool</b></h3>
The connection between the tool and your application is made through a repository token. Independent of the tool you are using, you will be provided with a repository token once you grant the platform access to a new git repository. The repository token is set as an environment variable either in your local installation or within your CI/CD platform.

In the case of Coveralls, it was necessary to install a node package and a script was added to the repository. The script can be modified to provide additional information on the application. Further details are provided in the <a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls specific blog post</a>.

Codecov merely required a specific set-up of the code coverage tool used.

Codacy was a bit special in this regard. Instead of installing a script or package within the application, users have to call a remote script. While it might seem more user friendly at the beginning, it has several disadvantages. Namely:
<ul>
 	<li aria-level="1">The script has to be called every time that the code coverage report is pushed to the Codacy account. If the script changes, it might result no longer be compatible with the coverage reports used and fail to upload those.</li>
 	<li aria-level="1">In case of an error, users do not have insights on what has gone wrong. In our case, Codacy was unable to access the right file within the repository and as a result, did not display coverage resorts. However, the script behaved as if it ran successfully.</li>
</ul>
<h3><b>Pipeline Creation</b></h3>
One heavily promoted feature within each code coverage tool is the possibility to integrate it directly within your existing CI/CD platform. To evaluate the use of each tool, we set-up a CI/CD pipeline for each tool within Codefresh. The process was highly similar across tools and resulted in the following pipeline for Codecov:

<a href="https://codefresh.io/wp-content/uploads/2021/02/image5.png"><img class="size-medium wp-image-18775" src="https://codefresh.io/wp-content/uploads/2021/02/image5-300x174.png" alt="codecov-pipeline" width="300" height="174" /></a>

Note that we have access to the live logging through the ‘Output’ section in the Codefresh UI.

This section specifically details the use of integrating either of the code coverage tools into Codefresh pipelines. The first steps of the Codecov pipeline are provided as an example. In Codefresh, each step is its own Docker image. At the beginning of standard pipelines, the git repository is cloned, a container image created and pushed to the user's container registry. These steps were the same for each tool.

{% raw %}
<pre>
version: "1.0"
# Stages can help you organize your steps in stages
stages:
  - "clone"
  - "build"
  - "test"

steps:
  clone:
    title: "Cloning repository"
    type: "git-clone"
    repo: "codefresh-contrib/codecov-sample-app"
    # CF_BRANCH value is auto set when pipeline is triggered
    # Learn more at codefresh.io/docs/docs/codefresh-yaml/variables/
    revision: "${{CF_BRANCH}}"
    git: "github"
    stage: "clone"

  build:
    title: "Building Docker image"
    type: "build"
    image_name: "codefresh-contrib/codecov-sample-app"
    working_directory: "${{clone}}"
    tag: "${{CF_BRANCH_TAG_NORMALIZED}}"
    dockerfile: "Dockerfile"
    stage: "build"
</pre>
{% endraw %}

Next, we had to run the tests, create coverage reports of our projects, and forward those to each platform. This is done in its own container image. For our application, we used the node image within each pipeline. The implementation for forwarding coverage reports between our Codefresh pipeline varied between Codecov, Coveralls, and Codacy.

<pre> 
test:
    title: "Running test"
    type: "freestyle" # Run any command
    image: "anaisurlichs/codecov-sample-app:master" # The image in which command will be executed
    working_directory: "${clone}" # Running command where code cloned
    commands:
      - "npm run test"
    stage: "test"

upload:
    title: "Pushing to Codecov"
    type: "freestyle" # Run any command
    image: "node:15.2" # The image in which command will be executed
    working_directory: "${clone}" # Running command where code cloned
    commands:
      - "ci_env=`curl -s https://codecov.io/env`"
      - "npm install codecov -g"
      - "codecov -t ${CODECOV_TOKEN} -f ./coverage/clover.xml"
    stage: "test"
</pre>

Note that it would have been best if each tool would provide their own container image that can be used within CI/CD pipelines instead of using the generic node image. This would have reduced the need for a custom workaround and makes it possible to optimize the process.
<h3><b>Let’s Recap</b></h3>
This post provided an overview and comparison of three different code analysis tools. Namely, Codecov, Coveralls and Codacy. All three tools have the same goal of accessing code coverage reports and generating curated insights over time.

When explored in more detail it becomes visible that all tools have a different focus on their implementation of features. This results in a tradeoff between access to features and ease of use. While Codacy is the most advanced tool of the three, it was more difficult to set-up and to navigate its UI. In contrast, Coveralls focuses on the minimum functionality needed to access and analyse code coverage reports. Comparing the free version of each tool, there is no significant difference between tools.

If you are interested in each tool specifically, we highly recommend you to have a look at our previous blog posts on:
<ul>
 	<li aria-level="1"><a href="https://codefresh.io/howtos/code-coverage-codecov/">Codecov</a></li>
 	<li aria-level="1"><a href="https://codefresh.io/howtos/code-coverage-reports-using-coveralls-codefresh/">Coveralls</a></li>
 	<li aria-level="1">And <a href="https://codefresh.io/howtos/codacy-coverage-reports/">Codacy</a></li>
</ul>
Each tool can be automated through Codefresh; simply by creating a pipeline for your project that integrates with the respective code coverage tool.

<a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&utm_medium=Post&utm_campaign=codeanalysiscomparison">Create Your Free Account today and try it out!</a>