Code Coverage Problem Statement Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Software maintenance costs are spiraling because few pieces of software can be changed with any degree of confidence that new bugs arent being introduced. For instance we have written bunch of tests scripts and when we execute we don't know what all those tests executes. There comes Code Coverage Tools which reports the test coverage either in the form of line or branch coverage that represents the amount of code that is being touched when a test is run.

This article is the First Phase of Code Coverage with automation. In this phase I will point out the most commonly used code coverage tools, their features and support they provides. Detail implementation will be discussed in the later phases.

What is Code Coverage?

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. To measure how well the program is exercised by a test suite, one or more coverage criteria are used as follows:

Function coverage - Has each function (or subroutine) in the program been called?

Statement coverage - Has each node in the program been executed?

Decision coverage (not the same as branch coverage.) - Has every edge in the program been executed? For instance, have the requirements of each branch of each control structure (such as in IF and CASE statements) been met as well as not met?

Condition coverage - Has each Boolean sub-expression evaluated both to true and false?

Condition/decision coverage - Both decision and condition coverage should be satisfied.

Parameter Value Coverage - In a method taking parameters, has all the common values for such parameter been considered?

Path coverage - Has every possible route through a given part of the code been executed?

Loop coverage - Has every possible loop been executed zero times, once, and more than once?

Code Coverage Tools/Add-ons

Here is the list of code coverage Add-ons with their features. In this article I will focus on the two most popular tools i.e. Emma and Cobertura, a java based open source tools.

Emma

EMMA is an open-source java tool that is used for measuring and reporting Java code coverage.

Features

EMMA is an open-source toolkit for measuring and reporting Java code coverage.

Supported coverage types: class, method, line, basic block. EMMA can detect when a single source code line is covered only partially.

Coverage stats are aggregated at method, class, package, and "all classes" levels.

Output report types: plain text, HTML, XML. All report types support drill-down, to a user-controlled detail depth. The HTML report supports source code linking.

Output reports can highlight items with coverage levels below user-provided thresholds.

Coverage data obtained in different instrumentation or test runs can be merged together.

EMMA does not require access to the source code and degrades gracefully with decreasing amount of debug information available in the input classes.

EMMA is quite fast: the runtime overhead of added instrumentation is small (5-20%) and the byte code instrumentor is very fast. Memory overhead is a few hundred bytes per Java class.

EMMA is 100% pure Java, has no external library dependencies, and works in any Java 2 JVM.

Can be Integrated with Maven

Emma Coverage

EMMA provides the support code coverage from small projects at home to enterprise level applications with unique features and supports i.e. Byte code instructions etc.

Emma Reporting

Various types of reporting Emma helps to generates, which can be html or plain text / xml etc.

Cobertura

Cobertura is a free open source Java tool that calculates the percentage of code accessed by tests.

Features

Cobertura is a free Java tool that calculates the percentage of Java code accessed by tests.

Can be executed from ant or from the command line.

Instruments Java byte code after it has been compiled.

Can generate reports in HTML or XML.

Shows the percentage of lines and branches covered for each class, each package, and for the overall project.

Shows the cyclomatic code complexity of each class, and the average cyclomatic code complexity for each package, and for the overall product.

Can sort HTML results by class name, percent of lines covered, percent of branches covered, etc. And can sort in ascending or descending order.

http://cobertura.sourceforge.net/

Cobertura Coverage

Cobertura measures test coverage by instrumenting a code base and watching which lines of code are and are not executed as the test suite runs. In addition to identifying untested code and locating bugs, Cobertura can optimize code by flagging dead, unreachable code and can provide insights into how an API operates in practice. Cobertura monitors tests by instrumenting the byte code with extra statements in order to trace out which lines are reached or not reached when test suite executes. It then produces a report in HTML or XML that shows exactly which packages, classes, methods, and individual lines of code are not being tested. We can write more tests for those specific areas.

Cobertura Reporting

The type of report generated is controlled by the format attribute of the report tag, which may be either html or xml. If the format is not supplied then it defaults to html.

<target name="coverage">

<cobertura-report format="xml" srcdir="${src.dir}" destdir="${build.coverage.dir}"/>

</target>

Comparison Cobertura Vs. Emma

Cobertura focuses on lines and branches (i.e. if and case statements)

Emma concentrates on byte code instructions, though you can also get line metrics.

Emma has a good write-up of their methodology

Both approaches result in fairly similar coverage results (unless your code does things like put multiple statements on the same line separated by semi-colons) but they'll almost always be a little different.

Eclipse plugins are available for both tools

Emma's report actually has less visual appeal than its Eclipse plugin

Cobertura, on the other hand, has some nice graphics

The Emma and Cobertura reports include metrics on classes, lines, and methods

Cobertura also has conditional statements and files while Emma includes blocks

Emma does not show the coverage if your tests don't explicitly test the built-in enum valueOf and values()methods- it shows up as 0% coverage

Cobertura will show those methods but mark them as N/A and not include them in your method coverage percentage

Others Code Coverage Tools

JaCoCo

JaCoCo is a free Java code coverage library. This mechanism allows in-memory pre-processing of all class files during class loading independent of the application framework

JaCoCo provides support to cover code for Statements, Branches, Instructions, Lines, Methods, and Classes etc.

JaCoCo is provided by the ElcEclimma.

JACOCO COMES WITH ANT TASKS to launch Java programs with execution recording and for creating coverage reports from the recorded data

THE JACOCO MAVEN PLUG-IN provides the JaCoCo runtime agent to your tests and allows basic report creation

Provides support to generate reports in various formats i.e. HTML, CSV, and XML etc.

Is open source free available java tool kit.

Code Cover

Code Cover helps to generate reports in HTML format. But this can convert or shipped into csv format.

Most importantly, Code Coverage can provide a feature to customize reports as needed and can also be generated text reports

It provides the features to cover code based on Branch level, Conditions, Loop and Statements etc.

Code Coverage is Java based Tool which is freely available

This can be configured and used with different Java development tools i.e. Eclipse

Code Coverage also provides a Correlation View to compare Test Cases with each other and their coverage.

Code Coverage also provides the functionality to export reports in desired formats.

Clover

JaCoCo is a free Java code coverage tool.

Can be integrated with Maven, Eclipse, and Ant etc.

Running the unit tests from Ant

Clover also allows testing time to be reduced by only running the tests that cover the application code that was modified since the previous build

DevPartner

Can be integrated with both Java and .Net

Automate coverage testing 

NCover

NCover is a .NET code coverage tool

works with any .NET supported language: C#, F#, VB.NET, Managed, C++, Iron Ruby and Iron Python

works with any type of testing from manual testing to automated unit tests

JSCoverage

JSCoverage is an open source JavaScript code coverage tool

JSCoverage works by instrumenting the JavaScript code used in web pages

JSCoverage works with any modern standards-compliant web browser - including Internet Explorer (IE 6, 7, and 8), Firefox, Opera, Safari, and Google Chrome - on Microsoft Windows and GNU/Linux

JSCoverage is free software

JSCoverage Reporting is done by using built in function (JSCoverage_Report) and can be created on specified location and can be in html format as follows

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.