junitperf

June 16, 2020 · View on GitHub

使用说明

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

AttrDescTypeDefaultRemark
threadsHow many threads are used to executeint1
warmUpPreparation timelong0Unit:mills
durationExecution timelong60_000(1 min)Unit:mills
latencyStatisticsStatistics implStatisticsCalculatorDefaultStatisticsCalculator
reporterReporter implReporterConsoleReporter

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:

TYPEDEMO
DefaultDefaultReporterTest
ConsoleConsoleReporterTest
HTMLHtmlReporterTest
MultiMultiReporterTest
DefineDefineReporterTest

@JunitPerfRequire

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

PropertiesDescriptionTypeDefaultRemarks
minbest costfloat-1If the fastest running time is higher than this value, it is regarded as a failure. Unit: ms
maxworst costfloat-1If the worst running time is higher than this value, it is regarded as failure. Unit: ms
averageavg costfloat-1If the average running time is higher than this value, it is regarded as a failure. Unit: ms
timesPerSecondThe minimum number of executions per secondint0If it is lower than this minimum number of executions, it is regarded as a failure.
percentilesLimitation on execution timeString[]{}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