refer: https://java.libhunt.com/project/wiremock/vs/moco
- wiremock usage:
- http://wiremock.org/docs/getting-started/
- https://smarttechie.org/2016/02/28/wiremock-mock-your-rest-apis/
- https://github.com/epages-de/restdocs-wiremock
- moco usage:
- https://github.com/dreamhead/moco/blob/master/moco-doc/usage.md
- Focus on JSON config & Java: https://github.com/dreamhead/moco/blob/master/moco-doc/apis.md
feature | wiremock | moco |
---|---|---|
running standalone | support | support |
configuration | mappings & __files | easier in .json file |
need restart? | yes | no |
Java API | yes | yes |
JUnit | yes | yes |
REST | yes | yes |
HTTPS | yes | yes |
Socket | no | yes |
Moco also have Java API which is designed in functional fashion that means you can composite any request or response easily.
server.request(and(by(uri("/target")), by(version(VERSION_1_0)))).response(with(text("foo")), header("Content-Type", "text/html"));
and these is a example how moco Java API integrated with JUnit, which support POJO and JSON Server:
public class MocoJunitPojoHttpRunnerTest {
private static HttpServer server;
static {
server = httpServer(12306);
server.response("foo");
}
@Rule
public MocoJunitRunner runner = MocoJunitRunner.httpRunner(server);
@Rule
public MocoJunitRunner runner = MocoJunitRunner.jsonHttpRunner(12306, "foo.json");
...
}
more details: https://github.com/dreamhead/moco/blob/master/moco-doc%2Fjunit.md
I suggest we can still perfer to use Moco over WireMock, because:
- we already use Moco in lots of projects and roll up to existing experiences
- so that we do not need learn more and investigate more realted usage and plugins (grunt & gradle one)...
- Moco provide more consistent way to stub server: Java API and .json file configuration
- most important concern about WireMock is: we need restart it whenever we did change mock and stub configuration inside .json file
- which is very harmful to developer experience, specially for Front-End development.
and what we need do if we still chose moco when integrate with spring-cloud? Maybe we need rewirte some code for spring cloud contract by using Moco Java API and I have not find any example with moco. But we can follow these exsiting examples in spring-cloud-contract/blob/master/samples/WiremockHttpsServerApplicationTests.java
@JimmLv, there is a typo in "VS Results" table, it's moco, not mock