gpt4 book ai didi

junit - 使用 junit perf 运行 junit 4 测试

转载 作者:行者123 更新时间:2023-12-04 23:58:04 30 4
gpt4 key购买 nike

可以将 Junitperf 与 junit4 一起使用吗?我有一个带有多个测试的简单 Junit4 测试类,我想对该类的单个测试进行 TimedTest。我该怎么做?

更清楚地说,我的 Junit4 类是这样的:

public class TestCitta {

@Test
public void test1 {}

@Test
public void test2 {}
}

对于 junit3,我应该这样写:

public class TestCittaPerformance {

public static final long toleranceInMillis = 100;

public static Test suite() {

long maxElapsedTimeInMillis = 1000 + toleranceInMillis;

Test testCase = new TestCitta("test2");

Test timedTest = new TimedTest(testCase, maxElapsedTimeInMillis);

return timedTest;
}

public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
}

用 Junit4?

最佳答案

我遇到了同样的问题,但尝试让它在不同的构建环境中运行并不幸运。因此,我使用自 JUnit 4 以来可用的 @Rule 功能来注入(inject)性能测试调用和使用注释的需求检查。结果它变成了一个小库,在这个项目中取代了 JUnitPerf,我以 的名字发布了它。 .如果您对这种方法感兴趣,可以在 https://github.com/lucaspouzac/contiperf 找到它。 .

关于junit - 使用 junit perf 运行 junit 4 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/323782/

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