Skip to content

Instantly share code, notes, and snippets.

@JimmyLv
Last active March 2, 2020 10:30
Show Gist options
  • Save JimmyLv/f73f9e9139e640ae0b86839b4e207ffa to your computer and use it in GitHub Desktop.
Save JimmyLv/f73f9e9139e640ae0b86839b4e207ffa to your computer and use it in GitHub Desktop.

Try to compare with moco:

refer: https://java.libhunt.com/project/wiremock/vs/moco

Usage

  1. wiremock usage:
  1. moco usage:

VS results

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

Migration & Integration?

https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_spring_cloud_contract_wiremock

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

Recommendations

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

@chaomao
Copy link

chaomao commented Oct 21, 2018

@JimmLv, there is a typo in "VS Results" table, it's moco, not mock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment