Java 如何使用wiremock模拟服务

Java 如何使用wiremock模拟服务,java,mocking,wiremock,Java,Mocking,Wiremock,我正在尝试使用Wiremock模拟我的服务A。但似乎缺少一些设置。我得到这个错误: <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 404 Not Found</title> </head> <body><h2>HTTP ERROR 404</h2>

我正在尝试使用Wiremock模拟我的服务A。但似乎缺少一些设置。我得到这个错误:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /__files/serviceA/endpointA Reason:
<pre>    Not Found</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.4.v20170414</a><hr/>

</body>
</html>

找不到错误404
HTTP错误404
访问/_文件/serviceA/endpointA时出现问题原因:
<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock</artifactId>
    <version>2.8.0</version>
</dependency>
找不到
404表示找不到端点位置

是否有任何一步一步的教程可以解释如何设置服务


谢谢。

有几种不同的方法:

  • 从命令行运行独立进程:
    java-jarwiremock-standalone-2.8.0.jar
    (参见 )
  • 创建具有以下依赖项的简单maven项目:

    private static final WireMockServer server = new WireMockServer(options().port(8080));
    
    public static void main(String[] args) {
        server.stubFor(post(urlEqualTo("/localsave")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
        server.start();
        //do some stuff
    }
    
  • 使用JUnit规则:

  • 您可以在此处找到所有信息:


    请告诉我这些信息是否足够您使用。

    有几种不同的方法:

  • 从命令行运行独立进程:
    java-jarwiremock-standalone-2.8.0.jar
    (参见 )
  • 创建具有以下依赖项的简单maven项目:

    private static final WireMockServer server = new WireMockServer(options().port(8080));
    
    public static void main(String[] args) {
        server.stubFor(post(urlEqualTo("/localsave")).willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
        server.start();
        //do some stuff
    }
    
  • 使用JUnit规则:

  • 您可以在此处找到所有信息:


    如果这对您来说是足够的信息,请告诉我。

    非常感谢。这很有帮助。您所解释的是针对独立服务器的,如果我在启动时为了测试而不得不使用其他服务运行模拟服务,该怎么办?您能更详细地解释一下您要测试什么吗?您是否使用JUnit进行测试?非常感谢。这很有帮助。您所解释的是针对独立服务器的,如果我在启动时为了测试而不得不使用其他服务运行模拟服务,该怎么办?您能更详细地解释一下您要测试什么吗?您是否使用JUnit进行测试?