Share

Cobertura

Tracker: Patches

5 Ignore trivial methods (optionally) - ID: 1576631
Last Update: Comment added ( nobody )

This patch implements a new feature in Cobertura that
allows trivial methods (getters, setters, etc.) to be
excluded from coverage metrics. This feature is useful
if you follow the philosophy that trivial getters and
setters "can't break" and therefore do not need unit tests.

The Ant task and command-line Main accept a new option
named "ignoreTrivial". If this option is set to
"true", methods that match the criteria below are
excluded from coverage. If the option is set to
"false", then all methods are included as Cobertura
does today.

The criteria for deciding a method is trivial are:

getters:
- method name begins with "get", "is", or "has"
- method accepts no arguments
- method return type is non-void
- method contains only bytecode instructions for
getting member field values

setters:
- method name begins with "set"
- method accepts exactly one argument
- method return type is void
- method contains only bytecode instructions for
setting member field values

initializers:
- method name is "<init>" (constructors and implicit
initializers)
- method contains only bytecode instructions for
setting member field values and calling initializer
method of immediate superclass (e.g. "super();")


Scott Frederick ( scottyfred ) - 2006-10-13 15:27

5

Open

None

Nobody/Anonymous

None

None

Public


Comments ( 2 )




Date: 2008-07-18 17:58
Sender: nobody

Logged In: NO

As first state, the criteria for excluding methods in this enhancement is
much more strict than just looking for "get" or "set" in the name. Only
methods that are truly trivial (only return the value of one data member or
only set the value of one data member) are excluded.




Date: 2007-04-14 08:18
Sender: fabriziogiudici


Why instead don't you introduce an annotation (or a config file) to mark
the methods to exclude one by one? Getter methods could be more complex
than a simple "return foo": for instance in a proxy or in a decorator there
is some logic inside.


Log in to comment.

Attached File ( 1 )

Filename Description Download
patch.txt Download

Change ( 1 )

Field Old Value Date By
File Added 198046: patch.txt 2006-10-13 15:27 scottyfred