Even though you are a hardcore Java Developer, you may need to have basic understanding on how to do Code Coverage
testing with some standalone tool or with simple Eclipse Plugin. In this tutorial we will go over how setup Code Coverage plugin in Eclipse and how to use it and check result.
This tutorial is best suite if you have any of below question:
- eclipse code coverage junit
- eclipse code coverage plugin
- best code coverage tool for Java in Eclipse
- how to configure EclEmma in eclipse
- EclEmma – Java Code Coverage for Eclipse
Let’s get started:
Step-1: Install EclEmma Java Code Coverage
Eclipse Plugin
What is EclEmma?
Click on Help -> Eclipse Marketplace…
Step-2
Type Code Coverage and hit Enter.
Step-3
- Click on install button next to ElcEmma Code Coverage
- Click
continue
and install plugin successfully - Restart Eclipse
And you are all set.
Step-4 Create JUnit test case and checkout Code Coverage
We are going to create JUnit test case for Fibonacci Series program. Make sure you copy and run it in your Eclipse environment before proceeding below.
If you have maven project then include below dependency. Follow steps here to convert your eclipse project to maven project.
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency>
For non-maven project, you could also download junit.jar
file and put it under your project’s /lib
folder.
Step-5
Create java test-case in class CrunchifyFibonacciSeriesTest.java
package crunchify.com.tests; import org.junit.Test; import crunchify.com.tutorial.CrunchifyFibonacci; /** * @author Crunchify.com */ public class CrunchifyFibonacciSeriesTest { int totalNumber = 5; @Test public void testCheckFibonacciRecursion() { CrunchifyFibonacci.fibonacciRecusion(totalNumber); } @Test public void testCheckFibonacciLoop() { CrunchifyFibonacci.fibonacciLoop(totalNumber); } }
Step-6
Right click
on file and run as Coverage As
-> JUnit Test
.
Step-7
Checkout the results under Coverage
Tab.
Also checkout file CrunchifyFibonacci.java
.
Hope you get complete picture on how to check junit code coverage in eclipse. This is the best way to install eclemma in eclipse IDE.