我正在对应用程序系统执行一些基于模型的测试,我想在指定的持续时间内执行我的测试(让我们说15分钟)。
我怎么能实现这个目标呢?
到目前为止,我的测试人员看起来像这样:
final Tester tester = new GreedyTester(new AgentSystemModelTests());
tester.setRandom(new Random());
tester.buildGraph();
tester.addListener(new StopOnFailureListener());
tester.addListener("verbose");
tester.addCoverageMetric(new TransitionPairCoverage());
tester.addCoverageMetric(new StateCoverage());
tester.addCoverageMetric(new ActionCoverage());
tester.generate(500);
tester.printCoverage();
答案 0 :(得分:2)
tester.generate(int n)
在Tester
类中定义为n
次调用generate()
的循环运行。
要在一段时间内运行测试,请考虑使用while
循环设置,以便在时间过后立即停止,如下所示。
final Duration TEST_DURATION = Duration.ofMinutes(15);
final Instant startTime = Instant.now();
final Instant finishTime = startTime.plus(TEST_DURATION);
final Tester tester = new GreedyTester(new AgentSystemModelTests());
tester.setRandom(new Random());
tester.buildGraph();
tester.addListener(new StopOnFailureListener());
tester.addListener("verbose");
tester.addCoverageMetric(new TransitionPairCoverage());
tester.addCoverageMetric(new StateCoverage());
tester.addCoverageMetric(new ActionCoverage());
// This is the magic predicate for the loop
while (Instant.now().isBefore(finishTime)) {
tester.generate();
}
tester.printCoverage();
来源:
GreedyTester.java which inherits RandomTester.java which inherits Tester.java