3 Strategies
In a typical model, there are multiple possible actions enabled in any given model
state.With offline test generation, the main idea is that the model is analyzed globally
and a test suite is derived that provides a traversal of the model.
The offline case is a special case of a more general form of testing where the
tester has a strategy selecting the action to be executed next or what result is to be
expected from the system under test. In addition to the model state, a tester also has
200 Testing Systems with Complex State
using System;
using NModel.Conformance;
using NModel.Terms;
namespace BagImplTestHarness
{
public class Stepper : IStepper
{
BagImpl bag = new BagImpl.BagImpl();
public Action DoAction(Action a)
{
switch (a.Name)
{
case ("Add"):
bag.Add((string)a[0]);
return null;
case ("Delete"):
bag.Delete((string)a[0]);
return null;
case ("Lookup_Start"):
int c = bag.Lookup((string)a[0]);
return Action.Create("Lookup_Finish", c);
case ("Count_Start"):
return Action.Create("Count_Finish", bag.Count);
default :
throw new Exception("Unexpected action " + a);
}
}
public void Reset()
{
bag = new BagImpl();
}
}
}
Figure 12.4. Bag stepper.
Systems with Complex State 201
using System;
using System.Collections.Generic;
using NModel.Terms;
using NModel.Execution;
using NModel;
namespace NModel.Conformance
{
public interface IStrategy
{
Set
ActionSymbols { get;}
IState CurrentState { get;}
bool IsInAcceptingState { get;}
void Reset();
bool IsActionEnabled(Action action, out string reason);
Action SelectAction(Set actionSymbols);
void DoAction(Action action);
}
}
Figure 12.
Pages:
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271