Install and use EclEmma, an Eclipse plugin for Java Code Coverage

In the previous tutorial, I introduced you all to a Maven plugin that allows us to generate reports on our code coverage. It’s a little inconvenient, if we’re adding Unit Test to our code and want to know how the code we’ve covered is, so we have to run the Maven jacoco:report every time then open the report .html file to see, it takes a lot of time, isn’t it? To solve this inconvenience, you can install an Eclipse plugin called EclEmma, ​​which allows us to see visual code coverage in Eclipse. How it is in details, let’s learn about this plugin in this tutorial.

Install the EclEmma plugin

There are many ways to install the EclEmma plugin into Eclipse, one of which is the easiest to install from the Eclipse Marketplace Client. As follows:

In Eclipse, select Help and select Eclipse Marketplace… Eclipse Marketplace window will appear, you search EclEmma, ​​the results are as follows:

Install and use EclEmma, an Eclipse plugin for Java Code Coverage

Please click the Install button to install this plugin!


Use

For the EclEmma plugin, you do not need to configure anything. This plugin can be used after installation.

Once installed, you will see that our Eclipse will have more modes available for Code Coverage, in addition to the existing Eclipse Run and Debug modes:

Install and use EclEmma, an Eclipse plugin for Java Code Coverage

As an example for using this EclEmma plugin, I will take the project that I created in the tutorial Initialize Mock object using @Mock annotation of Mockito.

Install and use EclEmma, an Eclipse plugin for Java Code Coverage

To check Code Coverage for this project, just select the project, then click on the Coverage mode on the Eclipse toolbar. Or you can right click on the project, select Coverage As, then select JUnit Test.

As such, a new tab will display Code Coverage under the Eclipse Editor as follows:

Install and use EclEmma, an Eclipse plugin for Java Code Coverage

In this tab, as you see, similar to JaCoCo Maven Plugin, look at the Coverage column, we can see how many % of code we have coverage, how many not. 61.4% is the percentage of Code Coverage of this example project.

Double click on each class, you will see details of this report open in the Eclipse editor as follows:

Install and use EclEmma, an Eclipse plugin for Java Code Coverage

Very intuitive, don’t you? Just running Coverage mode with Eclipse, we can see the Code Coverage result of our code. Our mission is only focus on improving it.

Install and use EclEmma, an Eclipse plugin for Java Code Coverage
Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
3Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.