How to perform code coverage using Eclipse?
How to perform code coverage with Eclipse?
There are many ways to instrument your test automation code and with many tools. The code coverage tool you pick mostly depends on the programming language. In other words, it depends on the language used to write your automation code.
Code Coverage Video Tutorial
EclEmma: Java Code Coverage(JaCoCo)
EclEmma is a free coverage tool for Eclipse, available under the Eclipse Public License. The tool is non-invasive. It does not require modifying your project files or any instrumentation set up as such.
Steps to Install the Plugin
Install EclEmma plugin for Eclipse.
Launch marketplace from your Eclipse menu select Help >> Eclipse Marketplace.
Search for EclEmma and click on the Go button.
Hit on Install for EclEmma Java Code Coverage.
Follow the steps and instructions in the installation wizard.
You may need to restart Eclipse after the plugin is installed.
Code Coverage Configuration
Once you restart Eclipse, in the Coverage window, choose the entries for the code coverage analysis scope as shown below:
The plugin supports many launch types. In this example, I’m using the TestNG test launch type. You can use for other launch types like Java applications, JUnit test,s etc.
Run the TestNG tests. Alternatively, you can run the tests with the Coverage As option.
Coverage View
The Coverage view shows all analyzed Java items as shown below. It can be opened from the Window >> Show View >> Other… >> Java category menu.
The tool also supports the export of coverage sessions in many formats, like HTML, XML, CSV, etc.
Code Coverage Metrics
JaCoCo
JaCoCo is a code coverage library for Java, created by the EclEmma team.
- https://www.jacoco.org/jacoco/trunk/index.html