net.sourceforge.cobertura.metrics.api
Interface CoverageCalculator

All Known Implementing Classes:
AbstractCoverageCalculator

public interface CoverageCalculator

Specification for how to calculate test coverage rates. Typical usage would be along the lines in the example shown below:

     
         // Acquire a CoverageCalculator
         CoverageCalculator calc = new SomeCoverageCalculator();

         // Start running the tests, and add execution steps for
         // all SourceLocations the tests.
         //
         // This is done in quite another form in reality, but
         // corresponding pseudo-code is shown below.
         UnitTestRunner runner = new SomeParticularTestRunner(config);
         List<InstrumentedTest> allTestsInProject = getAllInstrumentedTestsInProject();

         for(InstrumentedTest currentTest : allTestsInProject) {

             // Add the listener
             currentTest.addSourceLocationListener(calc.getSourceLocationListener());

             // Now run the test
             runner.execute(currentTest);
         }

         // Create some filters to define which measurements we are interested in.
         final SourceLocationFilter somePackageFilter = new SourceLocationFilter("some\\.package\\.name");
         final SourceLocationFilter someClassFilter = new SourceLocationFilter("some\\.package\\.name, "SomeClass");

         // Calculate some coverage rates.
         double allPackageLineCoverage = calc.getCoverage(somePackageFilter, CoverageType.LINE);
         double allPackageBranchCoverage = calc.getCoverage(somePackageFilter, CoverageType.BRANCH);
         double allClassLineCoverage = calc.getCoverage(someClassFilter, CoverageType.LINE);
         double allClassBranchCoverage = calc.getCoverage(someClassFilter, CoverageType.BRANCH);
     
 

Author:
Lennart Jörelid, jGuru Europe AB

Method Summary
 double getCoverage(SourceLocationFilter filter, CoverageType type)
          Convenience method, retrieving Coverage rate as a supplied type
 Rate getCoverageRate(SourceLocationFilter filter, CoverageType type)
          Retrieves the coverage rate for the supplied CoverageType.
 SourceLocationListener getSourceLocationListener()
          Retrieves a SourceLocationListener used to record execution steps ("hits"/"touches") of all SourceLocations within tests into this CoverageCalculator.
 

Method Detail

getCoverageRate

Rate getCoverageRate(SourceLocationFilter filter,
                     CoverageType type)
Retrieves the coverage rate for the supplied CoverageType.

Parameters:
filter - The SourceLocationFilter defining which CoverageRecords should be included in the retrieved Rate.
type - The CoverageType for which coverage is desired.
Returns:
the coverage Rate for the given CoverageType.

getCoverage

double getCoverage(SourceLocationFilter filter,
                   CoverageType type)
Convenience method, retrieving Coverage rate as a supplied type

Parameters:
filter - The SourceLocationFilter defining which CoverageRecords should be included in the retrieved Rate.
type - The CoverageType for which coverage is desired.
Returns:
the coverage, given as a value between 0 and 1.

getSourceLocationListener

SourceLocationListener getSourceLocationListener()
Retrieves a SourceLocationListener used to record execution steps ("hits"/"touches") of all SourceLocations within tests into this CoverageCalculator.

Returns:
a SourceLocationListener dumping its event data updates into this CoverageCalculator.


Copyright © 2013–2015 Cobertura. All rights reserved.