⛵️Junit performance rely on junit5 and jdk8+.(java 性能测试框架。性能测试。压测。测试报告生成。)
⛵️Junit performance rely on junit5 and jdk8+.(java 性能测试框架。性能测试。压测。测试报告生成。)
junitperf 是一款为 java 开发者设计的性能测试框架。
可以和 Junit5 完美契合。
使用简单,便于项目开发过程中的测试实用。
提供拓展,用户可进行自定义开发。
支持 I18N
支持多种报告生成方式,支持自定义
Junt5 完美支持,便于 Java 开发者使用
jdk1.8 及其以上版本
Junit5 及其以上版本
com.github.houbb
junitperf
2.0.7
public class HelloWorldTest {
@JunitPerfConfig(duration = 1000)
public void helloTest() throws InterruptedException {
Thread.sleep(100);
System.out.println("Hello Junit5");
}
}指定测试时的属性配置。(必填项)
| 属性 | 说明 | 类型 | 默认值 | 备注 |
|---|---|---|---|---|
| threads | 执行时使用多少线程执行 | int | 1 | |
| warmUp | 准备时间 | long | 0 | 单位:毫秒 |
| duration | 执行时间 | long | 60_000(1分钟) | 单位:毫秒 |
| latencyStatistics | 统计实现 | StatisticsCalculator | DefaultStatisticsCalculator | |
| reporter | 报告实现 | Reporter | ConsoleReporter |
使用如下:
public class JunitPerfConfigTest {
/**
* 2个线程运行。
* 准备时间:1000ms
* 运行时间: 2000ms
* @throws InterruptedException if any
*/
@JunitPerfConfig(threads = 2, warmUp = 1000, duration = 2000)
public void junitPerfConfigTest() throws InterruptedException {
System.out.println("junitPerfConfigTest");
Thread.sleep(200);
}
}这里主要是对于性能测试统计的输出方式。 支持以下方式:
| 方式 | 案例 |
|---|---|
| 默认方式 | DefaultReporterTest |
| 命令行 | ConsoleReporterTest |
| HTML | HtmlReporterTest |
| 组合方式 | MultiReporterTest |
| 自定义方式 | DefineReporterTest |
指定测试时需要达到的要求。(选填项)
| 属性 | 说明 | 类型 | 默认值 | 备注 |
|---|---|---|---|---|
| min | 最佳的运行耗时 | float | -1 | 最快的运行耗时如果高于这个值,则视为失败。单位:毫秒 |
| max | 平均的运行耗时 | float | -1 | 最坏的运行耗时如果高于这个值,则视为失败。单位:毫秒 |
| average | 平均的运行耗时 | float | -1 | 平均的运行耗时如果高于这个值,则视为失败。单位:毫秒 |
| timesPerSecond | 每秒的最小执行次数 | int | 0 | 如果低于这个最小执行次数,则视为失败。 |
| percentiles | 对于执行耗时的限定 | String[] | {} | percentiles={"20:220", "30:250"}。20% 的数据执行耗时不得超过 220ms;30% 的数据执行耗时不得超过 250ms; |
使用如下:
…大致如下:
…页面如下:
后期会进行样式调整。
方法的执行顺序会影响到最终的报告显示顺序。
如果你想严格指定同一个类方法的执行顺序,推荐使用 Test Execution Order 的方式。
@TestMethodOrder 需要 junit5 在 5.4 及其以后版本
com.github.houbb
junitperf
1.0.3
I18N 功能中的中文 properties 文件直接使用 UTF-8 格式。
如果你下载本项目进行测试,出现中文乱码。
idea 用户请勾选上图中的选项
【Setting】=》【File Encoding】勾选上 ascii 转换
gen-test-plugin 自动生成测试案例的 maven 插件
内存使用统计
支持线程的 sync 同步执行
优化 html 输出中的英文,支持 I18N
优化 html 输出中的格式,所有格式对齐
No open issues yet, or sync has not completed.