可以将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?
发布于 2010-04-01 01:22:43
我也有同样的问题,但我不太幸运,试图让它在不同的构建环境中运行。因此,我使用了从JUnit 4开始提供的@Rule特性来使用注释注入性能测试调用和需求检查。它变成了一个小型库,在这个项目中取代了JUnitPerf,我以contiperf的名字发布了它。如果你对这种方法感兴趣,你可以在https://github.com/lucaspouzac/contiperf找到它。
发布于 2011-11-11 17:46:31
如果你已经有了junit4,为什么不使用contiperf呢?它会做你想做的事情,并带有注解。
POM是这样的。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>测试类如下所示
public class PersonDAOTest {
@Rule
public ContiPerfRule i = new ContiPerfRule();实际的测试是这样的
@Test
@PerfTest(invocations = 1, threads = 1)
@Required(max = 1200, average = 250)
public void test() {发布于 2011-05-23 18:15:23
或者您可以使用注释:@Test(timeout=1000)
https://stackoverflow.com/questions/323782
复制相似问题