我有一系列针对web应用程序的功能测试,这些测试可以正确运行,但每个测试都需要使用@BeforeClass和@AfterClass注释提供的类级设置和拆卸,因此需要JUnit 4.0或更高版本。
现在,我想使用这些功能测试中的一小部分来执行负载测试,这些功能测试模拟大量用户请求web应用程序的相关页面。为了让每个用户在JWebUnit中都有自己的“模拟浏览器”,我需要在JUnitPerf中使用一个TestFactory来实例化被测试的类,但是由于JUnit 4测试是用@Test注释的,而不是从TestCase派生的,所以我得到了一个TestFactory must be constructed with a TestCase class异常。
有没有人成功地在JUnit 4上使用了JUnitPerf及其TestFactory?有什么秘方可以让它发挥作用呢?
发布于 2008-09-19 03:39:12
您需要一个支持JUnit4的TestFactory。我在下面包含了一个。
import junit.framework.JUnit4TestAdapter;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import com.clarkware.junitperf.TestFactory;
class JUnit4TestFactory extends TestFactory {
static class DummyTestCase extends TestCase {
public void test() {
}
}
private Class<?> junit4TestClass;
public JUnit4TestFactory(Class<?> testClass) {
super(DummyTestCase.class);
this.junit4TestClass = testClass;
}
@Override
protected TestSuite makeTestSuite() {
JUnit4TestAdapter unit4TestAdapter = new JUnit4TestAdapter(this.junit4TestClass);
TestSuite testSuite = new TestSuite("JUnit4TestFactory");
testSuite.addTest(unit4TestAdapter);
return testSuite;
}
}https://stackoverflow.com/questions/95506
复制相似问题