Can JMeter mock HTTP request

前端 未结 2 1292
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 21:32

I want to Mock HTTP requests, meaning sending real request to real server, but ignore (not wait) and override the response with a dummy res

相关标签:
2条回答
  • 2020-12-11 21:47

    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

    0 讨论(0)
  • 2020-12-11 21:53

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题