如何将JUnitPerf与JWebUnit和JUnit 4结合使用? [英] How do I use JUnitPerf with JWebUnit and JUnit 4?

查看:49
本文介绍了如何将JUnitPerf与JWebUnit和JUnit 4结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对正常运行的Web应用程序进行了一系列功能测试,但是每个功能测试都需要使用 @BeforeClass @AfterClass 批注提供的类级别设置和拆卸.,因此需要JUnit 4.0或更高版本.

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应用程序相关页面的用户.为了使每个用户在JWebUnit中都有自己的模拟浏览器",我需要在JUnitPerf中使用TestFactory来实例化测试中的类,但是由于JUnit 4测试使用 @Test 进行了注释,而不是从 TestCase 派生而来,我得到一个 TestFactory必须使用TestCase类异常构造.

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. 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.

有人成功地将JUnitPerf及其TestFactory与JUnit 4结合使用了吗?使它全部起作用的秘诀是什么?

Is anyone successfully using JUnitPerf and its TestFactory with JUnit 4? And what is the secret sauce that lets it all work?

推荐答案

您需要一个JUnit4感知的TestFactory.我在下面列出了一个.

You need a JUnit4 aware 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;
    }

}

这篇关于如何将JUnitPerf与JWebUnit和JUnit 4结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆