CodeCover

Velocity Context Reference

Overview

In the templates for VelocityReport, you can access java objects, its members and even its methods. Velocity doesn't care for types, but java does, so you will get TypeErrors, InvocationErrors and so on, far away from the template, if you're not careful with the types and the spelling, as Velocity let's every context name it does not recognised unreplaced. Methods are called as known from many programming languages by [contextName].[methodName([parameters])]

Objects by Context name

String

Javas String class. See the Java documentation for details.

now

The current date. See the Java documentation of Date if you need more details

dateFormatter

The DateFormat of the current locale. See the Java documentation of DateFormat for more details.

session

The test session this report is generated for. Methods of session you probably want to use are:

Method name Explanation
String getComment(); returns the comment set for this test session.
String getName(); returns the name of this test session.
Date getDate() returns the date of this test session

testcases

A List of testcases this report is generated for. Methods of TestCase you probably want to use are:

Method name Explanation
String getComment(); returns the comment set for this testcase.
String getName(); returns the name of this test case.
Date getDate() returns the date of this test case

topmostHierarchyLevel

currentHierarchyLevel

The HierarchyLevel at the top (in java, its the topmost package) and the one the output file written at this moment mainly belongs to (if such exists, otherwise it's also the one at the top).

Method Description
String getName() The name of the hierarchy level
String getType().getInternalName() The name of the the type of the hierarchy level
List<HierarchyLevel> getChildren() The children of this hierarchy level or an empty list, if there are none

hierarchyLevels

A List of all hierarchyLevels that are successors of topmostHierarchyLevel meaning its children, their children, ... Access it as any other list and use for each item of the list (which is a hierarchyLevel) the methods mentioned above.

hierarchyLevelTypeCounters

This List<NoPerHierarchyLevelType> has counted the times each HierarchyLevelType occurs. You may want to use a foreach-loop

#foreach( $hltc in $hierarchyLevelTypeCounters)
    $hltc.HierarchyLevelType.EnglishName
    $hltc.Number
#end

sorter

The sorter enables you to sort any List in an order you define in the template, during runtime. This works in two steps. First, you associate each item you want to sort with a sorting key.

void setKey(Object object, double key)
void setKey(Object object, int key)
void setKey(Object object, String key)

These methods set the key of the object to key. If a key was already set for this object, it is overwritten
Items with numbers are sorted ascending followed by items with string keys sorted lexicographically. Items without a key come last in the order they were. After you have set all keys, call

void sort(List list)

to execute the sorting.

coverageMetrics

All CoverageMetrics that are supported by the selected session, stored in a List. Each coverageMetric in that list has (among others) the following methods:

Method name Explanation
CoverageResult getCoverage(List<TestCase> testCases, HierarchyLevel hierarchyLevel) returns a CoverageResult (see below)
String getName(); returns the name of this CoverageMetric.
String getDescription() returns the description of this CoverageMetric.

CoverageResult gives you the ratio between covered and uncovered by providing the methods

Method name Explanation
int getCoveredItems() returns the number of covered items
int getTotalItems() returns the total number of items

code

With the call

List<ExtractOfCodeFile> getCoveredCode (HierarchyLevel level,
                                        List<TestCase> testCases,
                                        List<CoverageMetric> metrics)

you get colored code, separated in files and lines. ExtractOfCodeFile has the methods

String getFileName()
List<TextLine> getTextLines()

and each TextLine has the methods

Method name Explanation
int getLineNo() returns the line number of this line
String getText() returns the text in this line, enriched with html-tags for coloring
long getExecutions() returns how often this line was executed