|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnz.ac.waikato.modeljunit.ModelTestCase
public class ModelTestCase
Test a system, based on a finite state machine (FSM) model of that system.
This class provides several methods that use model-based testing techniques
to automatically generate test suites for a system under test (SUT)
from an FSM model of that system. To use these methods, you write a
special FSM class (see FsmModel
) that models part of the behaviour of
your SUT, then pass an instance of that class to one of the test
generation methods (eg. randomWalk(int)
).
It will analyse the structure of your FSM model, then call various
sequences of methods in your model to ensure that it is well tested.
Each action method of your FSM can change the state of the FSM,
and can also perform some tests on the SUT and change its state.
So your FSM class is actually performing two roles:
(1) Model: defining a simplified FSM view of the behaviour of your SUT;
(2) Adaptor: mapping each transition of that FSM to a concrete test
of your SUT.
TODO:
Field Summary | |
---|---|
static double |
DEFAULT_RESET_PROBABILITY
Deprecated. During random walk (including buildGraph), this is the default probability of doing reset() rather than choosing a random transition. |
static long |
FIXEDSEED
Deprecated. |
Constructor Summary | |
---|---|
ModelTestCase(FsmModel model)
Deprecated. Constructs an FSM model from the given FsmModel object. |
Method Summary | |
---|---|
static void |
addCoverageMetric(CoverageMetric cover)
Deprecated. Add a coverage listener. |
void |
allRoundTrips(int length)
Deprecated. Same as allRoundTrips(length), but uses a fixed seed for the random number generator. |
void |
allRoundTrips(int length,
java.util.Random rand)
Deprecated. Uses a greedy random walk to try and test all loops in the model. |
boolean |
buildGraph()
Deprecated. Equivalent to buildGraph(new Random(FIXEDSEED)). |
boolean |
buildGraph(java.util.Random rand)
Deprecated. Equivalent to buildGraph(new Random(FIXEDSEED), 10000). |
boolean |
buildGraph(java.util.Random rand,
int maxTransitions)
Deprecated. Finish building the graph. |
protected void |
continueBuildGraph(Transition tr,
int action)
Deprecated. Records a transition in the graph, if it is not already there. |
java.util.BitSet |
currentEnabledActions()
Deprecated. Return the bitset of all actions that are enabled in the current state. |
protected boolean |
doAction(int index)
Deprecated. Try to take the given Action from the current state. |
protected int |
doGreedyRandomAction(java.util.Random rand)
Deprecated. |
int |
doGreedyRandomActionOrReset(java.util.Random rand,
boolean testing)
Deprecated. |
protected int |
doRandomAction(java.util.Random rand)
Deprecated. Take any randomly-chosen Action that is enabled. |
int |
doRandomActionOrReset(java.util.Random rand,
boolean testing)
Deprecated. Randomly take an enabled transition, or do a reset with a certain probability (see getResetProbability() ). |
void |
doReset(boolean testing)
Deprecated. Reset the FSM to its initial state. |
protected void |
doReset(java.lang.String reason,
boolean testing)
Deprecated. Reset the FSM to its initial state. |
float |
enabled(int index)
Deprecated. Is Action number 'index' enabled? Returns 0.0 if Action number 'index' is disabled, or a positive number if it is enabled. |
protected int |
fsmFindAction(java.lang.String name)
Deprecated. Looks up an Action by name and returns its number. |
protected java.lang.Object |
getActionName(int index)
Deprecated. Returns the name of the given Action. |
java.util.List<CoverageMetric> |
getCoverageMetrics()
Deprecated. A list of all the current coverage listeners |
protected java.lang.Object |
getCurrentState()
Deprecated. Returns the current state of the implementation under test. |
int |
getFailedTests()
Deprecated. Returns the number of test failures. |
int |
getFailureVerbosity()
Deprecated. The amount of information printed when a test fails. |
InspectableGraph |
getGraph()
Deprecated. Returns the graph of the FSM model. |
protected java.lang.Object |
getModel()
Deprecated. Returns the model object that is begin tested. |
protected java.lang.Class |
getModelClass()
Deprecated. Returns the FSM class that is the test model. |
protected java.lang.String |
getModelName()
Deprecated. Returns the name of the FSM class that is the test model. |
protected int |
getNumActions()
Deprecated. The total number of Actions. |
double |
getResetProbability()
Deprecated. The probability of spontaneously doing a reset rather than a normal transition during random walks etc. |
int |
getVerbosity()
Deprecated. Says how many progress messages will be printed. |
Vertex |
getVertex(java.lang.Object state)
Deprecated. Maps a state to a vertex object of the FSM graph. |
void |
greedyRandomWalk(int length)
Deprecated. |
void |
greedyRandomWalk(int length,
java.util.Random rand)
Deprecated. |
protected void |
loadModelClass(java.lang.Class fsm)
Deprecated. Loads the given class and finds its @Action methods. |
void |
printFailure(int priority,
java.lang.String msg)
Deprecated. Print failure messages, when a test/tests fail. |
void |
printGraphDot(java.lang.String filename)
Deprecated. Saves the FSM graph into the given file, in DOT format. |
void |
printProgress(int priority,
java.lang.String msg)
Deprecated. Print progress messages, during FSM-based testing. |
void |
printWarning(java.lang.String msg)
Deprecated. Print a warning, during analysis of the FSM class. |
void |
randomWalk(int length)
Deprecated. Calls fsmRandomWalk/3 with FIXEDSEED so that tests are repeatable. |
void |
randomWalk(int length,
java.util.Random rand)
Deprecated. Does a random walk through a finite state machine. |
static void |
removeAllCoverageMetrics()
Deprecated. Remove all coverage listeners. |
static boolean |
removeCoverageMetric(CoverageMetric cover)
Deprecated. Remove a coverage listener. |
static void |
resetCoverageMetrics()
Deprecated. Reset all the coverage statistics. |
void |
setFailureVerbosity(int failureVerbosity)
Deprecated. Sets the amount of information printed when tests fail. |
void |
setResetProbability(double prob)
Deprecated. Set the probability of doing a reset during random walks. |
void |
setVerbosity(int verbosity)
Deprecated. Sets the level of progress messages that will be printed as this class builds the FSM graph and generates tests. |
protected void |
startBuildGraph()
Deprecated. Starts to build the FSM graph by exploring the fsm object. |
static java.lang.String |
stateName(java.lang.Object state)
Deprecated. Converts a state into a name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double DEFAULT_RESET_PROBABILITY
public static final long FIXEDSEED
Constructor Detail |
---|
public ModelTestCase(FsmModel model)
model
- Method Detail |
---|
protected int fsmFindAction(java.lang.String name)
name
- The name of an Action.
public int getFailedTests()
public double getResetProbability()
public void setResetProbability(double prob)
If this is set to 0.0, then resets will only be done when we reach a dead-end state (no enabled actions). This means that if the FSM contains a loop that does not have a path back to the initial state, then the random walks may get caught in that loop forever. For this reason, a non-zero probability is recommended.
The default probability is DEFAULT_RESET_PROBABILITY
.
prob
- Must be at least 0.0 and less than 1.0.public int getVerbosity()
public void setVerbosity(int verbosity)
verbosity
- 0..3public int getFailureVerbosity()
public void setFailureVerbosity(int failureVerbosity)
failureVerbosity
- 0..3protected java.lang.Class getModelClass()
protected java.lang.String getModelName()
public InspectableGraph getGraph()
public Vertex getVertex(java.lang.Object state)
protected java.lang.Object getModel()
protected java.lang.Object getCurrentState()
protected java.lang.Object getActionName(int index)
protected int getNumActions()
public void printWarning(java.lang.String msg)
public void printProgress(int priority, java.lang.String msg)
priority
- 1..3public void printFailure(int priority, java.lang.String msg)
priority
- 1..3public static void resetCoverageMetrics()
public static void addCoverageMetric(CoverageMetric cover)
public static boolean removeCoverageMetric(CoverageMetric cover)
public static void removeAllCoverageMetrics()
public java.util.List<CoverageMetric> getCoverageMetrics()
protected void loadModelClass(java.lang.Class fsm)
protected void startBuildGraph()
protected void continueBuildGraph(Transition tr, int action)
tr
- A possibly new transition (and state).public boolean buildGraph(java.util.Random rand, int maxTransitions)
Note that this method traverses the graph as it explores its shape, and this traversal is likely to increase any coverage statistics that are being recorded. For example, transition coverage will normally be 100% after this method returns. If you want to measure the coverage of a short traversal, you should call this method to explore the graph, then reset the coverage measures to zero before doing the traversal.
rand
- A random generator to choose the exploration path.
public boolean buildGraph(java.util.Random rand)
public boolean buildGraph()
public void printGraphDot(java.lang.String filename) throws java.io.FileNotFoundException
filename
- The filename should end with ".dot".
java.io.FileNotFoundException
public static java.lang.String stateName(java.lang.Object state)
state
-
public void doReset(boolean testing)
testing
- protected void doReset(java.lang.String reason, boolean testing)
reason
- Why the reset was performed (an adjective).testing
- False means we are just exploring the graph, so the
fsm object could skip the actual tests if it wants.public float enabled(int index)
index
- Index into the fsmActions array.
public java.util.BitSet currentEnabledActions()
protected boolean doAction(int index)
index
- Index into the fsmTransitions array.
protected int doRandomAction(java.util.Random rand)
rand
- The Random number generator that controls the choice.
public int doRandomActionOrReset(java.util.Random rand, boolean testing)
getResetProbability()
).
rand
- The Random number generator that controls the choice.
public void randomWalk(int length)
public void randomWalk(int length, java.util.Random rand)
reset()
method of the FSM to start
from the initial state again.
If you want to test a different path each time this
is called, then pass new Random()
as the
third parameter. If you want to test the same path
each time (this makes the test results more predictable),
then pass new Random(fixedSeed)
.
(fsmRandomWalk(fsm,length)
does this for you).
length
- The number of transitions to test.rand
- A random number generator to control the traversal.protected int doGreedyRandomAction(java.util.Random rand)
public int doGreedyRandomActionOrReset(java.util.Random rand, boolean testing)
public void greedyRandomWalk(int length)
public void greedyRandomWalk(int length, java.util.Random rand)
public void allRoundTrips(int length)
length
- The number of test steps to do.public void allRoundTrips(int length, java.util.Random rand)
length
- The number of test steps to do.rand
- The random number generator used to choose paths.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |