Eolinker provides comprehensive support for mock apis. Other mock Servers that require installation and configuration are not mentioned, so why build your own mock Server?
The Api information is as follows. You can remove the root path from the URL and write the Api address directly. Configure the address prefix of the online environment and the test environment in the project. Just switch.
In the API edit page, Advanced Mock, enter the rules for the mock. Eolinker mock is based on the mockjs to change, but the same rules, rules can refer to http://mockjs.com/examples.html here
After editing, go back to the API details page and you’ll see a URL under the mock tag. Just copy it into the project. Because the address prefix is uniform, you can configure a unified test prefix in the project as just described, and change it to the production environment prefix when it goes online. Restful support is nice. Seems to be the only mock Server I’ve seen so far that supports restful?
When used in the project, it looks like this (just write a simple demo) :
view plain
copy
- public class MockServerTest {
- @Test
- public void testMockServer() throws IOException {
- mockClient.when(
- request()
- .withPath(“http://mock.eolinker.com/TPivSvI55cabdf9f2243a023dc6a76ec9514dc38084c19d?uri=/bestedu/course/primarySchool”)
- .withMethod(“POST”)
- // .withHeader(new Header(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN))
- // .withQueryStringParameter(new Parameter(“my-token”, “12345”))
- ).respond(
- response()
- .withStatusCode(200)
- .withBody(expected)
- );
- CloseableHttpClient client = HttpClients.createDefault();
- HttpGet httpGet = new HttpPost(“http://mock.eolinker.com/TPivSvI55cabdf9f2243a023dc6a76ec9514dc38084c19d?uri=/bestedu/course/primarySchool”);
- CloseableHttpResponse response = client.execute(httpGet);
- // Verify that the output is correct
- InputStream content = response.getEntity().getContent();
- InputStreamReader inputStreamReader = new InputStreamReader(content);
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String responseText = bufferedReader.readLine();
- assertThat(responseText, equalTo(expected));
- }
- }
In addition to returning mock data, eolinker also validates the request method and parameters, and prompts if something is wrong, which is cool. But, the verification of mock is only available in the enterprise version, hoping that the technical boss can approve it by then.
Conclusion:
Do not repeat the wheel, now a lot of people advocate their own to do a set of services ah what, research is still ok, really work or simple and rough hand with the best. Besides, remote working is being promoted now, and Eolinker is doing ok in this area.