nz.ac.waikato.modeljunit
Class Tester

java.lang.Object
  extended by nz.ac.waikato.modeljunit.Tester
Direct Known Subclasses:
AllRoundTester, LookaheadTester, RandomTester

public abstract class Tester
extends java.lang.Object

An abstract superclass for all the test generation algorithms. Each subclass must implement a generate() method that generates the next step in a test sequence.

Note that many test generation algorithms use randomness, so this class provides a setter and getter for a random number generator. By default this is set to new Random(FIXEDSEED), so that test generation is deterministic.

Author:
marku

Field Summary
static long FIXEDSEED
           
protected  Model model_
          The model from which tests will be generated.
protected  java.util.Random rand_
          A Random number generator for use in test generation.
 
Constructor Summary
Tester(FsmModel fsm)
          A convenience constructor that puts a Model wrapper around an FsmModel.
Tester(Model model)
          Create a test generator for the given model.
 
Method Summary
 CoverageMetric addCoverageMetric(CoverageMetric metric)
          This is equivalent to addListener(metric), but more convenient.
 ModelListener addListener(ModelListener listener)
          A convenience method that adds a listener object.
 ModelListener addListener(java.lang.String name)
          A convenience method for adding known listeners and coverage metrics.
 void addListener(java.lang.String name, ModelListener listen)
          Deprecated. Use addListener(listener) instead.
 GraphListener buildGraph()
          Equivalent to buildGraph(10000).
 GraphListener buildGraph(int maxSteps)
          Equivalent to buildGraph(MaxSteps,true).
 GraphListener buildGraph(int maxSteps, boolean clear)
          Calls generate() repeatedly until the graph seems to be complete.
 GraphListener buildGraphBreadthFirst(int maxDepth, boolean clear)
          Generate a graph using a breadth-first approach with optimisations.
abstract  int generate()
          Generate one more test step in the current sequence.
 void generate(int length)
          Generate some test sequences, with the given total length.
abstract  java.lang.String getDescription()
          A brief description of this test generation algorithm.
 Model getModel()
           
abstract  java.lang.String getName()
          The name of this test generation algorithm.
 java.util.Random getRandom()
          Get the random number generator that is used for test generation.
 void printCoverage()
          Prints the name and toString message from each coverage metric.
 void reset()
          Performs a user-requested reset of the model.
 void setRandom(java.util.Random rand)
          This allows you to specify a random number generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIXEDSEED

public static final long FIXEDSEED
See Also:
Constant Field Values

model_

protected Model model_
The model from which tests will be generated.


rand_

protected java.util.Random rand_
A Random number generator for use in test generation.

Constructor Detail

Tester

public Tester(Model model)
Create a test generator for the given model.

Parameters:
model - Must be non-null.

Tester

public Tester(FsmModel fsm)
A convenience constructor that puts a Model wrapper around an FsmModel.

Parameters:
fsm - Must be non-null.
Method Detail

getName

public abstract java.lang.String getName()
The name of this test generation algorithm.


getDescription

public abstract java.lang.String getDescription()
A brief description of this test generation algorithm.


getModel

public Model getModel()
Returns:
The model that is driving the test generation.

getRandom

public java.util.Random getRandom()
Get the random number generator that is used for test generation.


setRandom

public void setRandom(java.util.Random rand)
This allows you to specify a random number generator. The default is to use new Random(FIXEDSEED), so that test generation is repeatable (that is, each instance of this class will generate the same test sequences).

Parameters:
rand - A non-null instance of Random.

addListener

public ModelListener addListener(java.lang.String name)
A convenience method for adding known listeners and coverage metrics. This is equivalent to getModel().addListener(name). See the Factory class for the set of known names.

Parameters:
name - The name of a known listener.
Returns:
The listener that has been added (now or earlier).

addListener

public void addListener(java.lang.String name,
                        ModelListener listen)
Deprecated. Use addListener(listener) instead.


addCoverageMetric

public CoverageMetric addCoverageMetric(CoverageMetric metric)
This is equivalent to addListener(metric), but more convenient.

Parameters:
metric - A non-null coverage metric to add.
Returns:
metric, or a previously-added metric with the same name (if any).

addListener

public ModelListener addListener(ModelListener listener)
A convenience method that adds a listener object. This is equivalent to getModel().addListener(listener).

Parameters:
listener - Must be non-null.
Returns:
The listener that has been added (now or earlier).

printCoverage

public void printCoverage()
Prints the name and toString message from each coverage metric. They are printed in alphabetical order.


reset

public void reset()
Performs a user-requested reset of the model.


generate

public abstract int generate()
Generate one more test step in the current sequence. This may reset and start a new test sequence if necessary.

Returns:
the number of the action taken, or -1 if a reset was done.

generate

public void generate(int length)
Generate some test sequences, with the given total length. The default implementation of this just calls generate() length times.

Parameters:
length -

buildGraph

public GraphListener buildGraph()
Equivalent to buildGraph(10000).


buildGraph

public GraphListener buildGraph(int maxSteps)
Equivalent to buildGraph(MaxSteps,true).


buildGraph

public GraphListener buildGraph(int maxSteps,
                                boolean clear)
Calls generate() repeatedly until the graph seems to be complete.

Note that this method uses a fresh random number generator (with FIXEDSEED) to avoid modifying the random number generator getRandom() that is used for test generation.

Parameters:
maxSteps - An upper bound on the number of calls to generate, to avoid eternal exploration of large graphs.
clear - If this is true, the TODO and DONE flags on each transition of the graph are cleared after the graph is built. This is recommended, so that algorithms like GreedyTester get a fresh view of the graph.
See Also:
GraphListener.isComplete()

buildGraphBreadthFirst

public GraphListener buildGraphBreadthFirst(int maxDepth,
                                            boolean clear)
Generate a graph using a breadth-first approach with optimisations.

Note that this method uses a fresh random number generator (with FIXEDSEED) to avoid modifying the random number generator getRandom() that is used for test generation.

The approach taken by this method is to maintain two queues:

Note that this function is incomplete and will be available in a subsequent release.

Parameters:
maxDepth - An upper bound on the depth to explore, to avoid eternal exploration of large graphs.
clear - If this is true, the TODO and DONE flags on each transition of the graph are cleared after the graph is built. This is recommended, so that algorithms like GreedyTester get a fresh view of the graph.
See Also:
GraphListener.isComplete()


Copyright © 2009 ModelJUnit Project. All Rights Reserved.