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.

Advanced Topics 269<br />

TestResult RunTest(int k)<br />

{<br />

Sequence trace = Sequence.EmptySequence;<br />

Action o = null;<br />

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

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

{<br />

if (isAsync && o == null && !obs.IsEmpty) o = obs.Dequeue();<br />

if (o != null)<br />

{<br />

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

string reason = "";<br />

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

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

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

}<br />

else<br />

{<br />

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

if (a == null)<br />

{<br />

if (isAsync)<br />

{<br />

Action w = strategy.SelectAction(new Set(waitAction));<br />

int obsTimeout = (w == null ? 0 : (int)w[0]);<br />

if (w != null){ trace = trace.Add(w); strategy.DoAction(w);}<br />

if (!obs.TryDequeue(obsTimeout, out o))<br />

if (strategy.IsInAcceptingState)<br />

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

else<br />

else o = timeoutAction;<br />

}<br />

else<br />

{<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 />

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

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

}<br />

Figure 16.6. Extension of the algorithm in Figure 12.7 with observable actions.<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!