...
| Code Block |
|---|
// require junit.jar
// require modeljunit.jar
import net.sourceforge.czt.modeljunit.*
import net.sourceforge.czt.modeljunit.coverage.*
class VendingMachineModel implements FsmModel {
def state = 0 // 0..,25,50,75,100
void reset(boolean testing) {state = 0}
boolean vendGuard() {state == 100}
@Action void vend() {state = 0}
boolean coin25Guard() {state <= 75}
@Action void coin25() {state += 25}
boolean coin50Guard() {state <= 50}
@Action void coin50() {state += 50}
}
def tester = new RandomTester(new VendingMachineModel())
tester.buildGraph()
tester.addListener "verbose",
new VerboseListener(tester.model)
tester.generate 20
|
When we run this script, we will see the randomly generated test transitions. The output will be:
...
| Code Block |
|---|
// ... as before to create the tester
def metrics = [
new ActionCoverage(),
new StateCoverage(),
new TransitionCoverage(),
new TransitionPairCoverage()
]
metrics.each {
tester.addCoverageMetric it
}
tester.addListener "verbose",
new VerboseListener(tester.model)
tester.generate 20
println 'Metrics Summary:'
metrics.each {
tester.model.printMessage "$it.name was $it"
}
|
...