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.

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

weight associated with each action that is initially some positive number. When an<br />

action is selected the corresponding weight is decremented by one. If, in a given state,<br />

the enabled actions are a1,...,ak with weights w1,...,wk, then an action ai is not<br />

selected if wi = 0, ai is selected with probability wi/(w1 +···+wk), otherwise.<br />

A useful analogy is with a box of colored marbles. Each action corresponds to<br />

a particular color and selecting an action corresponds to removing one randomly<br />

chosen marble from the box. This continues until the box is empty. This is a powerful<br />

and computationally cheap technique to produce test runs where weights are chosen<br />

in a way that matches a certain operational profile.<br />

Using groupings for pruning. A further technique that is a powerful way to deal<br />

with complex state is to use state or transition groupings. Suppose that each model<br />

state is mapped to an abstract value called a group label that characterizes some interesting<br />

properties of that state. The grouping function can, for example, be a coverage<br />

function. The grouping function may also be predicate abstraction in which case the<br />

group label is a sequence of Boolean values, or it may be a function that takes a sequence<br />

to a set. The idea is to dynamically keep track of all group labels encountered<br />

during test execution; an action that leads to a new group is prioritized over an action<br />

that does not. Here the driving factor is coverage of new groups, and the search<br />

space is pruned accordingly. The same idea can be applied to transitions.<br />

12.6 Exercises<br />

1. Correct the faulty bag implementation and rerun ct on it.<br />

2. The custom strategy shown in Section 12.4 chooses an action with maximum<br />

reward. Implement another SelectAction method that chooses an action with<br />

probability that is proportional to the reward.<br />

3. Implement a strategy for decrementing action weights discussed in Section<br />

12.5.4. In order to assign initial weights to actions, use state properties.<br />

4. Implement a strategy that records for each transition (s1,a,s2) an abstract<br />

transition (g(s1),g(a),g(s2)), where g is a grouping function; use GetHashCode<br />

for g. If in a given state, there are enabled actions that transition to states in<br />

new groups, select one of those actions randomly, otherwise choose any action<br />

randomly.<br />

*5. A state s is partially explored if there exists an unexplored action that is enabled<br />

in s. A state s is interesting either if it is partially explored or if there exists<br />

an explored path from s to a partially explored state. Implement a strategy that<br />

gives priority to actions that lead to interesting states.<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!