我对正确运行的 Web 应用程序进行了一系列功能测试,但每个测试都需要提供的类级别设置和拆卸@BeforeClass
and @AfterClass
注解,因此需要 JUnit 4.0 或更高版本。
现在我想使用少量的功能测试来执行负载测试,模拟大量用户请求 Web 应用程序的相关页面。为了让每个用户在 JWebUnit 中拥有自己的“模拟浏览器”,我需要在 JUnitPerf 中使用 TestFactory 来实例化被测试的类,但由于 JUnit 4 测试用注释@Test
而不是源自TestCase
,我得到一个TestFactory must be constructed with a TestCase class
例外。
有人成功地将 JUnitPerf 及其 TestFactory 与 JUnit 4 结合使用吗?让这一切发挥作用的秘诀是什么?
您需要一个支持 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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)