JMeter 可以模拟 HTTP 请求吗 [英] Can JMeter mock HTTP request

查看:20
本文介绍了JMeter 可以模拟 HTTP 请求吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟 HTTP 请求,这意味着将真实请求发送到真实服务器,但忽略(不等待)并用虚拟响应覆盖响应,

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 有很多很接近但还不够的工具,

JMeter have many tools which are close but not enough,

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

DummySampler plugin is close but not really sending request,

旧答案镜像服务器,这似乎与特定的 API 请求和响应无关.

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

JMeter 不模拟服务器.

JMeter does not simulate servers.

话虽如此,JMeter 2.3 有一个内置的镜像服务器——它接受任何 HTTP 请求并使用包含该请求的页面进行响应细节.

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.

如果服务器 B 不关心服务器 C 发回什么,那么您可以使用这是为了模拟"服务器 C.

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

我的回答关于忽略 HTTP 响应在 1 秒内添加运行时控制器并更新响应数据是一个有问题的解决方法,但可以工作.

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?

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

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) ?

推荐答案

最简单的选择是 WireMock这是非常强大和灵活的.

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

您可以通过添加 WireMock jar(连同与依赖项)到 JMeter Classpath 并运行 WireMockServer 来自 使用 Groovy 语言的 JSR223 测试元素.

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.

如果您对 Groovy 不太满意,您可以将 WireMock 作为独立 Java 应用程序 使用 OS 进程采样器

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

这篇关于JMeter 可以模拟 HTTP 请求吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆