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.

Systems with Complex State 205<br />

if (content.Contains(element))<br />

{<br />

Execute.AddCoveragePoint("in the bag")<br />

content = content.Remove(element);<br />

}<br />

else<br />

Execute.AddCoveragePoint("not in the bag")<br />

}<br />

You can define a method GetCoveragePoints in your custom strategy as<br />

follows. (A concrete example of a custom strategy definition is shown in the<br />

next section.) It is assumed here that the strategy has a field called model<br />

that references a given model program. The reserved name for getting all the<br />

coverage points that are covered by executing an annotated action from a given<br />

state is "CoveragePoints".<br />

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

{<br />

Bag cps;<br />

model.GetTargetState(s, a, "CoveragePoints", out cps);<br />

return cps;<br />

}<br />

Note that the target state of the transition is irrelevant in this context; only<br />

the bag of all the coverage points that were covered is relevant and is returned.<br />

Action coverage. If you only care about covering the different actions, independent<br />

of the start state, then you can use the following coverage function. If the<br />

actions take no arguments then this coverage function is equivalent to the first<br />

one above.<br />

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

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

State coverage. A widely used notion of behavioral coverage is to visit all the<br />

different states of the state machine. You can implement a state coverage<br />

function as follows. It is useful to map states to their hash codes here, rather<br />

than keeping around full states as coverage points.<br />

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

{<br />

int stateHash = model.GetTargetState(s, a).GetHashCode();<br />

return new Bag(new Literal(stateHash));<br />

}<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!