Can JMeter mock HTTP request

戏子无情 提交于 2019-11-29 14:51:30
Dmitri T

The easiest option would be going for i.e. WireMock which is extremely powerful and flexible.

You can integrate it with JMeter by adding WireMock jar (along with dependencies) to JMeter Classpath and running the WireMockServer from the JSR223 Test Elements using Groovy language.

If you're not too comfortable with Groovy you can run WireMock as a standalone Java application using OS Process Sampler


import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

public class WireMockTest {

    public static void main(String[] args) {
        WireMockServer wireMockServer = new WireMockServer();
        configureFor("0.0.0.0", 8080);
        wireMockServer.start();
        StubMapping foo = stubFor(get(urlEqualTo("/wiretest"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withBody("Hello World")));
        wireMockServer.addStubMapping(foo);
    }
}

I manged to do it using previous post (https://stackoverflow.com/a/49130518/5210267), but succeed only after putting it in "bzm - Parallel Controller" and setting timeout to define time of WireMockServer's work: image example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!