27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

204 <strong>Testing</strong> Systems with Complex State<br />

12.4.1 Coverage points<br />

There are many ways to measure coverage. Coverage points provide a uniform way<br />

to handle different coverage measures. A coverage point is a part or property of<br />

a program used to measure coverage, by counting how many times it is executed,<br />

visited, or otherwise exercised. A state, an action, or a branch in the code could be<br />

a coverage point.<br />

Let us a consider a fixed explorable model program. Suppose that given a state<br />

s and an action a, one can calculate a collection of coverage points that are visited<br />

(covered) in the model program if a is executed from state s. In general, the same<br />

coverage point can be visited multiple times but the order in which the coverage<br />

points are visited is irrelevant; thus, the collection is intuitively a bag. A coverage<br />

point is represented by a term. The type of a function that, given a state and an action,<br />

computes a bag of coverage points is called a CoverageFunction and is defined in<br />

the N<strong>Model</strong>.Conformance namespace as follows. 1<br />

delegate Bag CoverageFunction(IState s, Action a);<br />

Coverage points can reflect structural coverage as well as behavioral coverage of<br />

the model program. Here are some concrete examples of some common notions of<br />

coverage. The first two are examples of structural coverage of the model program,<br />

whereas the remaining three are examples of behavioral coverage because they are<br />

independent of the structure of the model program.<br />

Vocabulary coverage. The simplest example of a coverage function is one that<br />

returns a bag containing just the action symbol. In other words, it is ignored<br />

from which state the action is explored and what arguments the action takes.<br />

Bag GetVocabularyCoverage(IState s, Action a)<br />

{ return new Bag(a.FunctionSymbol.AsTerm); }<br />

Annotation coverage. Suppose you want to cover different cases or code<br />

branches inside one action method. You can annotate the model program with<br />

explicit coverage points using the Execute.AddCoveragePoint method in order<br />

to record what case has been taken. The following example shows how to annotate<br />

the bag model in Figure 12.2 with two coverage points that distinguish<br />

between the two cases when an element that is to be deleted occurs in the bag<br />

or does not occur in the bag.<br />

[Action]<br />

static void Delete(string element)<br />

{<br />

1 A method type such as CoverageFunction is called a delegate in .NET.<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!