Apache JMeter driver for loadtest4j.
With a new or existing Maven project open in your favorite editor...
Add the library to your Maven project POM.
<dependency>
<groupId>org.loadtest4j.drivers</groupId>
<artifactId>loadtest4j-jmeter</artifactId>
<scope>test</scope>
</dependency>
Use either the Factory or the Builder.
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
LoadTester loadTester = JMeterBuilder.withUrl("https", "example.com", 443)
.withNumThreads(1)
.withRampUp(5)
.build();
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));
}
}
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.