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

查看:141
本文介绍了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秒钟内添加Runtime控制器并更新响应数据是一个有问题的解决方法,但是可以正常工作.

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 Request还是作为Mock HTTP Request的新采样器? Runtime Controller是否可以仅支持发送并停止等待响应(例如,使用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集成.以及相关性)到 JMeter类路径并运行 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 Process Sampler

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天全站免登陆