Skip to content

loadtest4j/loadtest4j-jmeter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loadtest4j-jmeter

Build Status Codecov Maven Central

Apache JMeter driver for loadtest4j.

Usage

With a new or existing Maven project open in your favorite editor...

1. Add the library

Add the library to your Maven project POM.

<dependency>
    <groupId>org.loadtest4j.drivers</groupId>
    <artifactId>loadtest4j-jmeter</artifactId>
    <scope>test</scope>
</dependency>

2. Create the load tester

Use either the Factory or the Builder.

Factory

LoadTester loadTester = LoadTesterFactory.getLoadTester();
# src/test/resources/loadtest4j.properties

loadtest4j.driver.domain = example.com
loadtest4j.driver.numThreads = 1
loadtest4j.driver.port = 443
loadtest4j.driver.protocol = https
loadtest4j.driver.rampUp = 5

Builder

LoadTester loadTester = JMeterBuilder.withUrl("https", "example.com", 443)
                                     .withNumThreads(1)
                                     .withRampUp(5)
                                     .build();

3. Write load tests

Write load tests with your favorite language, test framework, and assertions. See the loadtest4j documentation for further instructions.

public class PetStoreLT {

    private static final LoadTester loadTester = /* see step 2 */ ;

    @Test
    public void shouldFindPets() {
        List<Request> requests = List.of(Request.get("/pet/findByStatus")
                                                .withHeader("Accept", "application/json")
                                                .withQueryParam("status", "available"));

        Result result = loadTester.run(requests);

        assertThat(result.getResponseTime().getPercentile(90))
            .isLessThanOrEqualTo(Duration.ofMillis(500));
    }
}

Generate HTML reports

The driver instructs JMeter to write its JTL report file to ./results/loadtest4j-[timestamp]/result.jtl.

A standalone copy of JMeter can generate an HTML report from this file with the following command:

jmeter -g /path/to/result.jtl -o /path/to/html

You can also post-process the JTL file with any other compatible tool of your choice.