当前位置: 首页 > news >正文

MockServer简单使用记录

下载源码

下载git源码:git clone https://github.com/mock-server/mockserver.git

通过执行文件编译成jar包

./mvnw clean package
可能会报错。

启动命令

java -jar ./mockserver-netty-jar-with-dependencies.jar -serverPort 1080 -proxyRemotePort 80 -proxyRemoteHost www.mock-server.com -logLevel WARN

访问前台

http(s)://<host>:<port>/mockserver/dashboard
这里的端口设置是启动命令的serverPort:1080

增加挡板

附件里面有key=value模式,json模式,xml模式设置和请求案例
下面是jmx文档

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.2.1"><hashTree><TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"><stringProp name="TestPlan.comments"></stringProp><boolProp name="TestPlan.functional_mode">false</boolProp><boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp><boolProp name="TestPlan.serialize_threadgroups">false</boolProp><elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"><collectionProp name="Arguments.arguments"/></elementProp><stringProp name="TestPlan.user_define_classpath"></stringProp></TestPlan><hashTree><ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true"><stringProp name="ThreadGroup.on_sample_error">continue</stringProp><elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"><boolProp name="LoopController.continue_forever">false</boolProp><stringProp name="LoopController.loops">1</stringProp></elementProp><stringProp name="ThreadGroup.num_threads">1</stringProp><stringProp name="ThreadGroup.ramp_time">1</stringProp><boolProp name="ThreadGroup.scheduler">false</boolProp><stringProp name="ThreadGroup.duration"></stringProp><stringProp name="ThreadGroup.delay"></stringProp><boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp></ThreadGroup><hashTree><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-设置-key=value" enabled="false"><boolProp name="HTTPSampler.postBodyRaw">true</boolProp><elementProp name="HTTPsampler.Arguments" elementType="Arguments"><collectionProp name="Arguments.arguments"><elementProp name="" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">false</boolProp><stringProp name="Argument.value">{&#xd;&quot;id&quot;: &quot;test_mock&quot;,&#xd;&quot;httpRequest&quot;: {&#xd;&quot;path&quot;: &quot;/hello/mock&quot;,&#xd;&quot;method&quot;: &quot;POST&quot;,&#xd;&quot;queryStringParameters&quot;: [&#xd;{&#xd;&quot;name&quot;: &quot;param1&quot;,&#xd;&quot;values&quot;: [&quot;value1&quot;]&#xd;}&#xd;],&#xd;},&#xd;&quot;httpResponse&quot;: {&#xd;&quot;body&quot;: {&#xd;&quot;status&quot;: 200,&#xd;&quot;result&quot;: &quot;Welcome to mock server!&quot;&#xd;}&#xd;},&#xd;&quot;priority&quot;: 10&#xd;
}&#xd;
</stringProp><stringProp name="Argument.metadata">=</stringProp></elementProp></collectionProp></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/mockserver/expectation</stringProp><stringProp name="HTTPSampler.method">PUT</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree/><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-设置-json" enabled="false"><boolProp name="HTTPSampler.postBodyRaw">true</boolProp><elementProp name="HTTPsampler.Arguments" elementType="Arguments"><collectionProp name="Arguments.arguments"><elementProp name="" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">false</boolProp><stringProp name="Argument.value">{&#xd;&quot;id&quot;: &quot;test_mock_json&quot;,&#xd;&quot;httpRequest&quot;: {&#xd;&quot;path&quot;: &quot;/hello/mock&quot;,&#xd;&quot;method&quot;: &quot;POST&quot;,&#xd;&quot;headers&quot;: [&#xd;{&#xd;&quot;name&quot;: &quot;Content-Type&quot;,&#xd;&quot;values&quot;: [&quot;application/json&quot;]&#xd;}&#xd;],&#xd;&quot;body&quot;: {&#xd;&quot;type&quot;: &quot;JSON&quot;,&#xd;&quot;json&quot;: {&#xd;&quot;key&quot;: &quot;param1&quot;,&#xd;&quot;nested&quot;: {&#xd;&quot;nestedKey&quot;: &quot;nestedValue&quot;&#xd;}&#xd;}&#xd;}&#xd;},&#xd;&quot;httpResponse&quot;: {&#xd;&quot;body&quot;: {&#xd;&quot;status&quot;: 200,&#xd;&quot;result&quot;: &quot;Welcome to mock server!&quot;&#xd;}&#xd;},&#xd;&quot;priority&quot;: 10&#xd;
}&#xd;
</stringProp><stringProp name="Argument.metadata">=</stringProp></elementProp></collectionProp></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/mockserver/expectation</stringProp><stringProp name="HTTPSampler.method">PUT</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree/><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-设置-xml" enabled="true"><boolProp name="HTTPSampler.postBodyRaw">true</boolProp><elementProp name="HTTPsampler.Arguments" elementType="Arguments"><collectionProp name="Arguments.arguments"><elementProp name="" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">false</boolProp><stringProp name="Argument.value">{&#xd;&quot;id&quot;: &quot;test_mock_xml&quot;,&#xd;&quot;httpRequest&quot;: {&#xd;&quot;path&quot;: &quot;/xml/mock&quot;,&#xd;&quot;method&quot;: &quot;POST&quot;,&#xd;&quot;headers&quot;: [&#xd;{&#xd;&quot;name&quot;: &quot;Content-Type&quot;,&#xd;&quot;values&quot;: [&quot;application/xml&quot;]&#xd;}&#xd;],&#xd;&quot;body&quot;: {&#xd;&quot;type&quot;: &quot;STRING&quot;,&#xd;&quot;string&quot;: &quot;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&quot;&#xd;}&#xd;},&#xd;&quot;httpResponse&quot;: {&#xd;&quot;statusCode&quot;: 200,&#xd;&quot;body&quot;: &quot;&lt;response&gt;XML Response&lt;/response&gt;&quot;&#xd;},&#xd;&quot;priority&quot;: 10&#xd;
}&#xd;
</stringProp><stringProp name="Argument.metadata">=</stringProp></elementProp></collectionProp></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/mockserver/expectation</stringProp><stringProp name="HTTPSampler.method">PUT</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree/><ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true"><boolProp name="ResultCollector.error_logging">false</boolProp><objProp><name>saveConfig</name><value class="SampleSaveConfiguration"><time>true</time><latency>true</latency><timestamp>true</timestamp><success>true</success><label>true</label><code>true</code><message>true</message><threadName>true</threadName><dataType>true</dataType><encoding>false</encoding><assertions>true</assertions><subresults>true</subresults><responseData>false</responseData><samplerData>false</samplerData><xml>false</xml><fieldNames>true</fieldNames><responseHeaders>false</responseHeaders><requestHeaders>false</requestHeaders><responseDataOnError>false</responseDataOnError><saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage><assertionsResultsToSave>0</assertionsResultsToSave><bytes>true</bytes><sentBytes>true</sentBytes><url>true</url><threadCounts>true</threadCounts><idleTime>true</idleTime><connectTime>true</connectTime></value></objProp><stringProp name="filename"></stringProp></ResultCollector><hashTree/></hashTree><ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="线程组" enabled="true"><stringProp name="ThreadGroup.on_sample_error">continue</stringProp><elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true"><boolProp name="LoopController.continue_forever">false</boolProp><stringProp name="LoopController.loops">1</stringProp></elementProp><stringProp name="ThreadGroup.num_threads">1</stringProp><stringProp name="ThreadGroup.ramp_time">1</stringProp><boolProp name="ThreadGroup.scheduler">false</boolProp><stringProp name="ThreadGroup.duration">10</stringProp><stringProp name="ThreadGroup.delay"></stringProp><boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp></ThreadGroup><hashTree><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-测试-key=value" enabled="false"><elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true"><collectionProp name="Arguments.arguments"/></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/hello/mock?param1=value1</stringProp><stringProp name="HTTPSampler.method">POST</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree><HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true"><collectionProp name="HeaderManager.headers"><elementProp name="Content-Type" elementType="Header"><stringProp name="Header.name">Content-Type</stringProp><stringProp name="Header.value">application/json</stringProp></elementProp></collectionProp></HeaderManager><hashTree/></hashTree><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-测试-json" enabled="false"><boolProp name="HTTPSampler.postBodyRaw">true</boolProp><elementProp name="HTTPsampler.Arguments" elementType="Arguments"><collectionProp name="Arguments.arguments"><elementProp name="" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">false</boolProp><stringProp name="Argument.value">{&#xd;&quot;key&quot;: &quot;param1&quot;,&#xd;&quot;vvv&quot;:&quot;2222&quot;,&#xd;&quot;nested&quot;: {&#xd;&quot;nestedKey&quot;: &quot;nestedValue&quot;,&#xd;&quot;ccc&quot;:&quot;1111&quot;&#xd;}&#xd;
}</stringProp><stringProp name="Argument.metadata">=</stringProp></elementProp></collectionProp></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/hello/mock</stringProp><stringProp name="HTTPSampler.method">POST</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree><HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true"><collectionProp name="HeaderManager.headers"><elementProp name="Content-Type" elementType="Header"><stringProp name="Header.name">Content-Type</stringProp><stringProp name="Header.value">application/json</stringProp></elementProp></collectionProp></HeaderManager><hashTree/></hashTree><HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求-测试-xml" enabled="true"><boolProp name="HTTPSampler.postBodyRaw">true</boolProp><elementProp name="HTTPsampler.Arguments" elementType="Arguments"><collectionProp name="Arguments.arguments"><elementProp name="" elementType="HTTPArgument"><boolProp name="HTTPArgument.always_encode">false</boolProp><stringProp name="Argument.value">&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;</stringProp><stringProp name="Argument.metadata">=</stringProp></elementProp></collectionProp></elementProp><stringProp name="HTTPSampler.domain">192.168.145.128</stringProp><stringProp name="HTTPSampler.port">1080</stringProp><stringProp name="HTTPSampler.protocol">http</stringProp><stringProp name="HTTPSampler.contentEncoding"></stringProp><stringProp name="HTTPSampler.path">/xml/mock</stringProp><stringProp name="HTTPSampler.method">POST</stringProp><boolProp name="HTTPSampler.follow_redirects">true</boolProp><boolProp name="HTTPSampler.auto_redirects">false</boolProp><boolProp name="HTTPSampler.use_keepalive">true</boolProp><boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp><stringProp name="HTTPSampler.embedded_url_re"></stringProp><stringProp name="HTTPSampler.connect_timeout">1</stringProp><stringProp name="HTTPSampler.response_timeout"></stringProp></HTTPSamplerProxy><hashTree><HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true"><collectionProp name="HeaderManager.headers"><elementProp name="Content-Type" elementType="Header"><stringProp name="Header.name">Content-Type</stringProp><stringProp name="Header.value">application/xml</stringProp></elementProp></collectionProp></HeaderManager><hashTree/></hashTree><ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true"><boolProp name="ResultCollector.error_logging">false</boolProp><objProp><name>saveConfig</name><value class="SampleSaveConfiguration"><time>true</time><latency>true</latency><timestamp>true</timestamp><success>true</success><label>true</label><code>true</code><message>true</message><threadName>true</threadName><dataType>true</dataType><encoding>false</encoding><assertions>true</assertions><subresults>true</subresults><responseData>false</responseData><samplerData>false</samplerData><xml>false</xml><fieldNames>true</fieldNames><responseHeaders>false</responseHeaders><requestHeaders>false</requestHeaders><responseDataOnError>false</responseDataOnError><saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage><assertionsResultsToSave>0</assertionsResultsToSave><bytes>true</bytes><sentBytes>true</sentBytes><url>true</url><threadCounts>true</threadCounts><idleTime>true</idleTime><connectTime>true</connectTime></value></objProp><stringProp name="filename"></stringProp></ResultCollector><hashTree/><kg.apc.jmeter.vizualizers.CorrectedResultCollector guiclass="kg.apc.jmeter.vizualizers.TransactionsPerSecondGui" testclass="kg.apc.jmeter.vizualizers.CorrectedResultCollector" testname="jp@gc - Transactions per Second" enabled="true"><boolProp name="ResultCollector.error_logging">false</boolProp><objProp><name>saveConfig</name><value class="SampleSaveConfiguration"><time>true</time><latency>true</latency><timestamp>true</timestamp><success>true</success><label>true</label><code>true</code><message>true</message><threadName>true</threadName><dataType>true</dataType><encoding>false</encoding><assertions>true</assertions><subresults>true</subresults><responseData>false</responseData><samplerData>false</samplerData><xml>false</xml><fieldNames>true</fieldNames><responseHeaders>false</responseHeaders><requestHeaders>false</requestHeaders><responseDataOnError>false</responseDataOnError><saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage><assertionsResultsToSave>0</assertionsResultsToSave><bytes>true</bytes><sentBytes>true</sentBytes><url>true</url><threadCounts>true</threadCounts><idleTime>true</idleTime><connectTime>true</connectTime></value></objProp><stringProp name="filename"></stringProp><longProp name="interval_grouping">1000</longProp><boolProp name="graph_aggregated">false</boolProp><stringProp name="include_sample_labels"></stringProp><stringProp name="exclude_sample_labels"></stringProp><stringProp name="start_offset"></stringProp><stringProp name="end_offset"></stringProp><boolProp name="include_checkbox_state">false</boolProp><boolProp name="exclude_checkbox_state">false</boolProp></kg.apc.jmeter.vizualizers.CorrectedResultCollector><hashTree/></hashTree></hashTree></hashTree>
</jmeterTestPlan>
http://www.lryc.cn/news/274053.html

相关文章:

  • AI+金融:大模型引爆金融科技革命
  • 数据库(二)实验一:MySQL数据库的C/S模式部署
  • RLHF几大常用框架实践对比(trlx、deepspeedchat、colossalaichat)
  • Oracle/Myql批量操作
  • 关于一个web站点的欢迎页面
  • 1050. 鸣人的影分身(dp划分)
  • 51单片机点灯入门教程——2. 呼吸灯效果
  • shell脚本实现九九乘法表
  • CAAC无人机操作证考证报名流程及白底证件照片制作方法
  • RPC介绍
  • 23 导航栏
  • express框架搭建后台服务
  • 信息学奥赛一本通2067详解+代码
  • Java大数据hadoop2.9.2搭建伪分布式yarn资源管理器
  • 3D Gaussian Splatting复现
  • tf-idf +逻辑回归来识别垃圾文本
  • Oracle - 数据库的实例、表空间、用户、表之间关系
  • Java面试项目推荐,异构数据源数据流转服务DatalinkX
  • 一、Vue3组合式基础[ref、reactive]
  • unity网页远程手机游戏Inspector面板proxima
  • 聊聊spring事务12种场景,太坑了
  • mysql 数据查重与查重分页
  • 微服务(12)
  • ​iOS实时查看App运行日志
  • 【计算机毕业设计】SSM健身房管理系统
  • 嵌入式Linux之MX6ULL裸机开发学习笔记(IMX启动方式-启动设备的选择)
  • K8S Ingress-Nginx导出TCP端口
  • 索引类型-哈希索引
  • uniapp中组件库的Textarea 文本域的丰富使用方法
  • LLM、AGI、多模态AI 篇三:微调模型