我只是不能让org.mock-server运行。它给了我:
org.mockserver.client.netty.SocketConnectionException: Unable to connect to socket localhost/127.0.0.1:443下面是我的测试用例的代码:
private ClientAndServer mockServer;
@BeforeClass
public void startServer() {
mockServer = startClientAndServer(1080);
}
@Test
void downloadByUserShouldRetry() {
// given
new MockServerClient("localhost", 443)
.when(
request()
.withSecure(true)
.withMethod("GET")
.withPath("myUrl")
.withHeader("Authorization", "Bearer " + adminAccessToken),
exactly(1)
)
.respond(
response()
.withStatusCode(401)
.withHeaders(
new Header("Content-Type", "application/json; charset=utf-8"),
new Header("Cache-Control", "public, max-age=86400")
)
.withBody("{ message: 'incorrect username and password combination' }")
.withDelay(TimeUnit.SECONDS,1)
);发布于 2022-03-08 12:25:19
似乎我遇到了一个类似的问题。我使用一个MockServer静态实例进行了多个集成测试。
我在这个吉特布问题上找到了以下答案,这对我很有帮助:
mockServer.stop();
while (!mockServer.hasStopped(3,100L, TimeUnit.MILLISECONDS)){}基本上,在进入下一个测试之前,您正在等待服务器完全停止。这对我很有好处。
https://stackoverflow.com/questions/70092362
复制相似问题