Skip to content
Tools to write stress tests and benchmarks with Junit5.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Build Status badge

Tools to write stress tests and benchmarking with Junit5.

Getting started

You need to add a next dependency:


REST API stress testing

Let’s consider a simple web application :

tasks application

Here we can create tasks and sub-tasks with titles, estimates, and weights(position in the list). When we create a sub-task we need to evaluate weight and set the next value for creating the task, because exists a unique constraint on the SubTask table in the database.

If we don’t synchronize API then multiple concurrent requests might let us to ConstraintViolationException.

In this case, StressTestRunner provide you an ability to check synchronization of your API:

void concurrentThreadsSubTasks() {
                    .mode(ExecutionMode.TASK_EXECUTOR_MODE)  (1)
                    .timeout(5, TimeUnit.SECONDS) (2)
                    .threads(4)   (3)
                    .iterations(100)  (4)
                    .run(this::createSubTaskSingleTest); (5)

private void createSubTaskSingleTest() throws Exception {

    SubTask subTask = MvcRequester.on(mockMvc)
                                  .to("tasks/{id}/subtasks/create", TASK_ID)
                                  .withParam("title", "Make it safe!")
                                  .withParam("estimate", 30)

                       .extracting(SubTask::getTitle, SubTask::getEstimate)
                       .contains("Make it safe!", 30);
  1. test runner strategy (ThreadPoolExecutor based or Parallel Stream based)

  2. time limit for tests passing

  3. set threads count

  4. set count of runs.

  5. code of the one test iteration

JUnit5 Benchmark Extension

When you need to compare a performance of multiple methods, you can use TestBenchmark extension:

@EnableTestBenchmark  (1)
class EnableTestBenchmarkTest {

    @Fast (2)
    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)  (3)
    void testFast() throws InterruptedException {

    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testSlow() throws InterruptedException {
  1. enable test extension

  2. mark as Fast method which you expect will be faster

  3. set measurement and warm-up iterations

Example of the benchmarking: live benchmarking

If you measuring very fast methods (less than one milliseconds) you can use MeasureUnit annotation to set a unit of measurement profiling:

@MeasureUnit(unit = TimeUnit.NANOSECONDS)
class BenchmarkExtensionMeasureUnitTest {

    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testFast() {

    @TestBenchmark(measurementIterations = 15, warmupIterations = 10)
    void testSlow() throws InterruptedException {
You can’t perform that action at this time.