In the process of APP development, if you can add a function to simulate the return of server data naturally (without affecting the final APK) in the normal project code of the client, it will be very convenient to develop the client without relying on the server.

The Mock API provides a solution to this problem by allowing quick testing of APP functionality through predefined data generation rules, making it easy to develop both front and back end simultaneously.

First, what is a Mock?

In the world of software testing, a Mock means to simulate the behavior of a test object by some technical means in order to return a predesigned result.

Two, what’s the use of mocks?

First, mocks can be used to decouple test objects from external services (such as databases, third-party interfaces, etc.) so that test cases can run independently. This is especially important for both traditional monolithic applications and now popular microservices, because the presence of any external dependencies greatly limits the portability and stability of test cases. By mocking out external dependencies, you can improve both the portability and stability of test cases.

How to create Mock API service?

You can choose different Mock frameworks and tools for different test scenarios.

Mockito is a well-known unit testing framework based on object layer. Through Mockito, a large number of project testing configurations can be written to achieve comprehensive project testing services. However, its functions are too complex to be suitable for all projects.

2.WireMock is also a well-known tool in the field of interface testing abroad. Unlike Mockito at the object level, WireMock is a Mock testing tool for APIS. If Mocketo is the Swiss Army knife of unit testing and can Mock Everything, WireMock is designed for small projects. Support for HTTP response stubs, request validation, proxying/blocking, recording, and playback. But you still need to write a lot of Mock API rules, you can’t automatically generate data, and it’s a little less easy to use.

3. EoLinkereoLinker is the largest online interface management platform in China. It not only has very comprehensive interface management functions, but also can set the rules of Mock through UI interface, support the function methods of Mock JS and native JS, and simplify the writing operation of Mock API.

It is worth noting that eoLinker is an online SaaS service. Users can access the Mock service through the URL provided by eoLinker without any deployment. It is recommended to use the URL provided by eoLinker.

Other frameworks for similar Mock apis include OkHttp’s MockWebServer, Moco, and MockServer. Mockwebserver also falls into the category of embedded Mock frameworks, but its functionality is too simple. Moco and MockServer, although fully functional, require independent deployment and have no obvious advantages over the above products.