集成 WireMock 和 JMeter 时本地主机连接被拒绝
Localhost connection refused when integrating WireMock and JMeter
我正在尝试将 Wiremock 集成到 Jmeter 测试计划中,这样每次我执行测试计划时,它都会在开始时启动一个 WireMock 实例,然后启动 运行 我概述的测试。我遵循了这个答案 () 但我遇到的问题是我总是收到错误消息:
Response message:Non HTTP response message: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
据我所知,即使我在测试计划开始时在 JSR223 采样器中有以下代码,Wiremock 服务器也永远不会启动:
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("127.0.0.1", 8080);
wireMockServer.start();
StubMapping foo = stubFor(get(urlEqualTo("/some/thing"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
wireMockServer.addStubMapping(foo);
}
}
任何人都可以指出如何正确集成两者的正确方向,我已经尝试添加到类路径中,但我觉得我没有正确完成此操作或者我遗漏了一些东西
谢谢!
您正在定义 main
function 但我没看到您在哪里执行它。换句话说,您的 Wiremock 初始化代码根本没有得到执行。
您需要显式调用此 main
函数才能执行您的代码,要完成此操作,请将下一行添加到脚本的末尾:
WireMockTest.main()
完成后,JSR223 采样器将调用 main
函数内的代码,Wiremock 服务器将启动。
另一种选择是删除这些 class
和函数声明,只使用
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
WireMockServer wireMockServer = new WireMockServer();
configureFor("127.0.0.1", 8080);
wireMockServer.start();
StubMapping foo = stubFor(get(urlEqualTo("/some/thing"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
wireMockServer.addStubMapping(foo);
因为您在 JSR223 测试元素中定义的脚本不需要 entry point
查看 Apache Groovy - Why and How You Should Use It 文章以获取有关 Groovy JMeter 测试中脚本编写的更多信息。
我正在尝试将 Wiremock 集成到 Jmeter 测试计划中,这样每次我执行测试计划时,它都会在开始时启动一个 WireMock 实例,然后启动 运行 我概述的测试。我遵循了这个答案 (
Response message:Non HTTP response message: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
据我所知,即使我在测试计划开始时在 JSR223 采样器中有以下代码,Wiremock 服务器也永远不会启动:
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("127.0.0.1", 8080);
wireMockServer.start();
StubMapping foo = stubFor(get(urlEqualTo("/some/thing"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
wireMockServer.addStubMapping(foo);
}
}
任何人都可以指出如何正确集成两者的正确方向,我已经尝试添加到类路径中,但我觉得我没有正确完成此操作或者我遗漏了一些东西
谢谢!
您正在定义 main
function 但我没看到您在哪里执行它。换句话说,您的 Wiremock 初始化代码根本没有得到执行。
您需要显式调用此 main
函数才能执行您的代码,要完成此操作,请将下一行添加到脚本的末尾:
WireMockTest.main()
完成后,JSR223 采样器将调用 main
函数内的代码,Wiremock 服务器将启动。
另一种选择是删除这些 class
和函数声明,只使用
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
WireMockServer wireMockServer = new WireMockServer();
configureFor("127.0.0.1", 8080);
wireMockServer.start();
StubMapping foo = stubFor(get(urlEqualTo("/some/thing"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
wireMockServer.addStubMapping(foo);
因为您在 JSR223 测试元素中定义的脚本不需要 entry point
查看 Apache Groovy - Why and How You Should Use It 文章以获取有关 Groovy JMeter 测试中脚本编写的更多信息。