简体   繁体   English

如何将JUnitPerf与JWebUnit和JUnit 4一起使用?

[英]How do I use JUnitPerf with JWebUnit and JUnit 4?

I have a series of functional tests against a web application that correctly run, but each require the class level setup and teardown provided with the @BeforeClass and @AfterClass annotations, and hence require JUnit 4.0 or above. 我对正确运行的Web应用程序进行了一系列功能测试,但每个都需要使用@BeforeClass@AfterClass注释提供的类级别设置和拆解,因此需要JUnit 4.0或更高版本。

Now I want to perform load testing using a small number of these functional tests, which simulate a large number of users requesting the related page of the web application. 现在我想使用少量的这些功能测试来执行负载测试,这些测试模拟了大量用户请求Web应用程序的相关页面。 In order for each user to have their own "simulated browser" in JWebUnit, I need to use a TestFactory in JUnitPerf to instantiate the class under test, but since JUnit 4 tests are annotated with @Test instead of being derived from TestCase , I'm getting a TestFactory must be constructed with a TestCase class exception. 为了让每个用户在JWebUnit中拥有自己的“模拟浏览器”,我需要在JUnitPerf中使用TestFactory来实例化测试中的类,但由于JUnit 4测试是使用@Test注释而不是从TestCase派生的,所以我'获取TestFactory must be constructed with a TestCase class异常TestFactory must be constructed with a TestCase class

Is anyone successfully using JUnitPerf and its TestFactory with JUnit 4? 是否有人成功使用JUnitPerf及其TestFactory与JUnit 4? And what is the secret sauce that lets it all work? 什么是让它全部起作用的秘诀?

You need a JUnit4 aware TestFactory. 您需要一个知道JUnit4的TestFactory。 I've included one below. 我在下面加了一个。

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;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM