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 215<br />

TestResult RunTest(int k)<br />

{<br />

Sequence trace = Sequence.EmptySequence;<br />

Action o = null; // optional output from the stepper<br />

while (trace.Count < steps ||<br />

{<br />

(!strategy.IsInAcceptingState && trace.Count < maxSteps))<br />

if (o != null)<br />

{<br />

trace = trace.AddLast(o);<br />

string reason = "";<br />

if (strategy.IsActionEnabled(o, out reason)) //check conformance<br />

{ strategy.DoAction(o); o = null; }<br />

else<br />

return new TestResult(k, Verdict.Failure, reason, trace);<br />

}<br />

else<br />

{<br />

Action a = strategy.SelectAction(testerActionSymbols);<br />

if (a == null)<br />

if (strategy.IsInAcceptingState)<br />

return new TestResult(k, Verdict.Success, "", trace);<br />

else<br />

return new TestResult(k, Verdict.Failure,<br />

"Did not finish in accepting state", trace);<br />

else<br />

{<br />

strategy.DoAction(a);<br />

trace = trace.AddLast(a);<br />

if (!internalActionSymbols.Contains(a.FunctionSymbol))<br />

{<br />

try<br />

o = InvokeStepper(a);<br />

catch (Exception e)<br />

return new TestResult(k, Verdict.Failure, e.Message, trace);<br />

}<br />

}<br />

}<br />

}<br />

}<br />

Figure 12.7. Outline of the algorithm executing a single test run.<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!