Skip to content

Latest commit

 

History

History
191 lines (132 loc) · 6.5 KB

README-EN.md

File metadata and controls

191 lines (132 loc) · 6.5 KB

junitperf

使用说明

junitperf is a performance testing framework designed for java developers.

Maven Central Build Status Open Source Love

Why use it?

  • It fits perfectly with Junit5.

  • Simple to use, convenient for practical testing during project development.

  • Provide expansion, users can customize development.

Features

  • Support I18N

  • Support multiple report generation methods, support custom

  • Junt5 perfect support, easy for Java developers to use

CHANGELOG

CHANGELOG

v2.0.5 major change

  1. new feature for memory cost

Quick Start

Required

maven

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>junitperf</artifactId>
    <version>2.0.5</version>
</dependency>

hello world

hello world

  • demo
public class HelloWorldTest {

    @JunitPerfConfig(duration = 1000)
    public void helloTest() throws InterruptedException {
        Thread.sleep(100);
        System.out.println("Hello Junit5");
    }

}

Config

Annotation

@JunitPerfConfig

config for test

Attr Desc Type Default Remark
threads How many threads are used to execute int 1
warmUp Preparation time long 0 Unit:mills
duration Execution time long 60_000(1 min) Unit:mills
latencyStatistics Statistics impl StatisticsCalculator DefaultStatisticsCalculator
reporter Reporter impl Reporter ConsoleReporter

as following:

public class JunitPerfConfigTest {

    /**
     * two threads
     * Preparation time:1000ms
     * Execution time: 2000ms
     * @throws InterruptedException if any
     */
    @JunitPerfConfig(threads = 2, warmUp = 1000, duration = 2000)
    public void junitPerfConfigTest() throws InterruptedException {
        System.out.println("junitPerfConfigTest");
        Thread.sleep(200);
    }

}

Reporter types

This is mainly the output method for performance test latencyStatistics.

The following methods are supported:

TYPE DEMO
Default DefaultReporterTest
Console ConsoleReporterTest
HTML HtmlReporterTest
Multi MultiReporterTest
Define DefineReporterTest

@JunitPerfRequire

Specify the requirements to be met when testing. (Optional)

Properties Description Type Default Remarks
min best cost float -1 If the fastest running time is higher than this value, it is regarded as a failure. Unit: ms
max worst cost float -1 If the worst running time is higher than this value, it is regarded as failure. Unit: ms
average avg cost float -1 If the average running time is higher than this value, it is regarded as a failure. Unit: ms
timesPerSecond The minimum number of executions per second int 0 If it is lower than this minimum number of executions, it is regarded as a failure.
percentiles Limitation on execution time String[] {} percentiles={"20:220", "30:250"}。20% of the data execution time should not exceed 220ms; 30% of the data execution time should not exceed 250ms;

as following:

public class JunitPerfRequireTest {
    /**
     * Configuration: 2 threads running. Preparation time: 1000ms. Running time: 2000ms.
     * Requirements: The fastest should not be less than 210ms, the slowest should not be less than 250ms, the average should not be less than 225ms, and the number of operations per second should not be less than 4 times.
     * 20% of the data is not less than 220ms, and 50% of the data is not less than 230ms;
     *
     * @throws InterruptedException if any
     */
    @JunitPerfConfig(threads = 2, warmUp = 1000, duration = 2000)
    @JunitPerfRequire(min = 210, max = 250, average = 225, timesPerSecond = 4, percentiles = {"20:220", "50:230"})
    public void junitPerfConfigTest() throws InterruptedException {
        System.out.println("junitPerfConfigTest");
        Thread.sleep(200);
    }

}

Reporting method

Command line

Roughly as follows:

[INFO] 2018-01-14 22:16:31.419 [] - Started at:   2018-01-14 22:16:30.194
[INFO] 2018-01-14 22:16:31.419 [] - Invocations:  10
[INFO] 2018-01-14 22:16:31.420 [] - Success:  10
[INFO] 2018-01-14 22:16:31.420 [] - Errors:   0
[INFO] 2018-01-14 22:16:31.420 [] - Thread Count: 2
[INFO] 2018-01-14 22:16:31.421 [] - Warm up:      0ms
[INFO] 2018-01-14 22:16:31.421 [] - Execution time: 1000ms
[INFO] 2018-01-14 22:16:31.421 [] - Throughput:     10/s (Required: -1/s) - PASSED
[INFO] 2018-01-14 22:16:31.424 [] - Min latency:   200.2112ms (Required: -1.0ms) - PASSED
[INFO] 2018-01-14 22:16:31.424 [] - Max latency:    205.67862ms (Required: -1.0ms) - PASSED
[INFO] 2018-01-14 22:16:31.425 [] - Ave latency:    202.97829ms (Required: -1.0ms) - PASSED

HTML way

The page is as follows:

Later, style adjustments will be made.

junitperf-report-html.png

Relative Open-Source Framework

data-factory: Automatically generate test data

gen-test-plugin: Maven plugin to automatically generate test cases

Road-MAP

  • Memory usage latencyStatistics