摘要:本文将带你了解软件测试工具之轻量级的测试工具:ContiPerf,希望本文对大家学测试工具有所帮助
本文将带你了解软件测试工具之轻量级的测试工具:ContiPerf,希望本文对大家学测试工具有所帮助
ContiPerf是一个轻量级的测试工具,基于JUnit 4 开发,可用于效率测试等。
1、ContiPerf介绍
可以指定在线程数量和执行次数,通过限制最大时间和平均执行时间来进行效率测试,一个简单的例子如下:
public class ContiPerfTest { @Rule public ContiPerfRule i = new ContiPerfRule(); @Test @PerfTest(invocations = 1000, threads = 40) @Required(max = 1200, average = 250, totalTime = 60000) public void test1() throws Exception { Thread.sleep(200); } }
使用@Rule注释激活ContiPerf,通过@Test指定测试方法,@PerfTest指定调用次数和线程数量,@Required指定性能要求(每次执行的最长时间,平均时间,总时间等)。
也可以通过对类指定@PerfTest和@Required,表示类中方法的默认设置,如下:
@PerfTest(invocations = 1000, threads = 40) @Required(max = 1200, average = 250, totalTime = 60000) public class ContiPerfTest { @Rule public ContiPerfRule i = new ContiPerfRule(); @Test public void test1() throws Exception { Thread.sleep(200); } }
2、在maven中使用ContiPerf
配置方式如下:
[xml] view plain copy print?<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> <dependency> <groupId>org.databene</groupId> <artifactId>contiperf</artifactId> <version>2.1.0</version> <scope>test</scope> </dependency> </dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
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。
4、测试结果展示
测试的结果可以展示在浏览器中,如下:
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标软件测试之测试工具频道。
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号