JMeter 可以模拟 HTTP 请求吗

Can JMeter mock HTTP request

我想模拟 HTTP 请求,意思是发送 真实请求 真实服务器 ,但忽略(不等待)并覆盖响应带有虚拟响应,

JMeter 有很多接近但不够用的工具,

DummySampler 插件已关闭但并未真正发送请求,

似乎与特定 API 请求和响应无关的 old answer direct to Mirror Server

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 通过在 1 秒内添加运行时控制器并更新响应数据来忽略 HTTP 响应是一个有问题的解决方法,但可以工作。

是否有更好的插件或并行执行其他工具的选项?

打开 JMeter 的增强是否相关?如果是,它应该改进 HTTP 请求还是作为模拟 HTTP 请求的新采样器?运行时控制器是否可以仅支持发送并停止等待响应(例如使用 0 秒)?

最简单的选择是 WireMock,它非常强大和灵活。

您可以通过添加 WireMock jar (along with dependencies) to JMeter Classpath and running the WireMockServer from the JSR223 Test Elements using Groovy language.

将其与 JMeter 集成

如果您对 Groovy 不太满意,您可以 运行 WireMock 作为 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);
    }
}

我设法使用以前的 post () 做到了,但只有在将其放入 "bzm - Parallel Controller" 并设置超时以定义 WireMockServer 工作时间后才能成功: image example