ModelJUnit运行测试一段时间

时间:2018-01-10 13:10:18

标签: java testing junit model automated-tests

我正在对应用程序系统执行一些基于模型的测试,我想在指定的持续时间内执行我的测试(让我们说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();

1 个答案:

答案 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();

来源:

Tester.java

GreedyTester.java which inherits RandomTester.java which inherits Tester.java