anasoid / jmeter-as-code

Jmeter as code is the easy way to write jmeter test as code.
Apache License 2.0
32 stars 4 forks source link
code dsl java jmeter jmx performance performance-testing

Write Jmeter tests as code.

An API that give access to full Jmeter feature as code, All designed object in GUI can be written as code.

Build & Test Audit Coverage Lines of Code Security Rating Reliability Rating Maintainability Rating

Maven Central javadoc

Where to start

If you are new with Jmeter as code, try examples project and see documentation website.

A basic script example:
    TestPlanWrapper testPlan = TestPlanWrapper.builder()
        .addThread(ThreadGroupWrapper.builder()
            .addSampler(
                HTTPSamplerProxyWrapper.builder()
                    .withName("Home")
                    .withDomain("https://github.com")
                    .withProtocol("https")
                    .withPath("/anasoid")
                    .build())
            .build())
        .build();

  ApplicationTest applicationTest = new ApplicationTest(testPlanWrapper);

  applicationTest.run();
  //OR
  applicationTest.toJmx(new File("mytest.jmx"));
A basic script example using template:
    TestPlanWrapper testPlan = TestPlanWrapper.builder()
        .addThread(ThreadGroupWrapper.builder()
            .addSampler(new HomePage())
            .build())
        .build();

    ApplicationTest applicationTest = new ApplicationTest(testPlanWrapper);

    applicationTest.run();
    //OR
    applicationTest.toJmx(new File("mytest.jmx"));

class HomePage extends
    AbstractJmcTemplate<HTTPSamplerProxyWrapper, HTTPSamplerProxyWrapperBuilder<?, ?>> {

  @Override
  protected void prepareBuilder(HTTPSamplerProxyWrapperBuilder<?, ?> builder) {
    super.prepareBuilder(builder);
    builder.withName("Home")
        .withDomain("https://github.com")
        .withProtocol("https")
        .withPath("/anasoid");
  }

  @Override
  protected JmcWrapperBuilder<?> init() {
    return HTTPSamplerProxyWrapper.builder();
  }
}