ContiPerf是一个轻量级的测试工具,基于JUnit 4 开发,可用于效率测试等。

1、在maven中使用ContiPerf

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.databene</groupId>
            <artifactId>contiperf</artifactId>
            <version>2.1.0</version>
            <scope>test</scope>
        </dependency>

2、一个简单的例子

    //激活ContiPerf
    @Rule
    public ContiPerfRule i = new ContiPerfRule();

    @Test
    //指定调用次数/线程数
    @PerfTest(invocations = 100, threads = 20)
    //指定性能要求 每次执行的最长时间/平均时间/总时间
    @Required(max = 200, average = 100, totalTime = 2000)
    public void Test() {

        String s = UUID.randomUUID().toString();
        System.out.println(s);

    }

测试报告位置

3、主要参数介绍

1)PerfTest参数
@PerfTest(invocations = 300):执行300次,和线程数量无关,默认值为1,表示执行1次;
@PerfTest(threads=30):并发执行30个线程,默认值为1个线程;
@PerfTest(duration = 20000):重复地执行测试至少执行20s。
2)Required参数
@Required(throughput = 20):要求每秒至少执行20个测试;
@Required(average = 50):要求平均执行时间不超过50ms;
@Required(median = 45):要求所有执行的50%不超过45ms;
@Required(max = 2000):要求没有测试超过2s;
@Required(totalTime = 5000):要求总的执行时间不超过5s;
@Required(percentile90 = 3000):要求90%的测试不超过3s;
@Required(percentile95 = 5000):要求95%的测试不超过5s;
@Required(percentile99 = 10000):要求99%的测试不超过10s;
@Required(percentiles = "66:200,96:500"):要求66%的测试不超过200ms,96%的测试不超过500ms。

猜你喜欢

转载自blog.csdn.net/lw112190/article/details/109722323
今日推荐