gpt4 book ai didi

java - ModelJUnit运行测试一段时间

转载 作者:行者123 更新时间:2023-11-28 20:08:02 25 4
gpt4 key购买 nike

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

最佳答案

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

关于java - ModelJUnit运行测试一段时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48188244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com