Can JMeter mock HTTP request

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

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

JMeter have many tools which are close but not enough,

DummySampler plugin is close but not really sending request,

An old answer direct to Mirror Server which seems irrelevant for specific API requests and responses.

JMeter does not simulate servers.

Having said that, JMeter 2.3 has a built-in mirror server - it accepts any HTTP request and responds with a page containing the request details.

If server B does not care what server C sends back, then you could use this to "mock" server C.

My answer on ignoring HTTP response by adding Runtime controller with 1 second and updating the response data is a problematic workaround but can work.

Is there a better option available in plugins or executing some other tool in parallel?

Is opening an enhancement for JMeter is relevant and if so, should it improve HTTP Request or is it a new sampler as Mock HTTP Request? can Runtime controller support only sending and stop waiting for response (by using 0 seconds for example) ?

回答1:

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);     } } 


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