At present, the front and back end are separated from each other. Generally, the back end personnel design the interface definition first, and then the front end personnel can develop according to the interface definition. In the early stage, the front and back end develop independently and do not affect each other.

So the question is, if in the middle and late stages, the front-end development is finished, the back end is not finished, then the front end should be silly to wait for the back end development is finished and then the debugging test? By then, it will be too late and the quality of the front end will not be guaranteed. Typically, the back end will have a Mock test. The back end will provide interface virtual data so that the front end can test ahead of time and then connect the real data after the back end is developed.

TestableMock is an open source mocktool from Alibaba. It claims to be the lightest, simple, and comfortable Mock testing tool. It is very powerful and can be integrated with unit testing. This tool is for backend unit test integration and cannot be used as a Mock stand-alone test for the front end.

Maybe there are still people who are writing code to fake data, which is inefficient. Today, the stack leader introduced a simple Mock test method that allows the front-end to develop independently and simulate tests, and Postman can do it!

Create Mock Server

In this article, the stack length is demonstrated using the latest Postman 8.0.6 as an example.

Open Postman and go to the Mock Servers panel:

You can see the definition of Mock Server:

Mock servers let you simulate endpoints and their corresponding responses in a collection without actually setting up a back end.

Translation:

Mock servers allow you to simulate endpoints and their responses without setting up the back end.

Click the “Create New Mock Server” text to start creating a new Mock Server.

Here the stack length selects to create a new collection (or an existing collection), and then creates two new requests and the corresponding simulated response data.

Next, start the Mock Server configuration:

Enter the name of the Mock Server, select save the Server URL as an environment variable, and complete the creation of the Mock Server:

Once you’ve created it, you need to do two things:

1, add Mock Server sample responses for each request;

Example to add resources:

Go. PSTMN. IO/docs – exampl…

Send the Mock Server Url request.

The Mock Url looks like this:

41783d96-2f22-4ed6-ac64-62187a0ee521.mock.pstmn.io

This is a public network link, only with the network, the front end can be connected to test.

Make a Mock request

Open the Collections panel:

You can see the Javastack-Mock collection that has been created, along with the two previously created requests and the default sample response, and the mock Server Url environment variable that has been created.

Now that the default sample response is generated, let’s Mock the request directly. Select a GET request and initiate the request:

As you can see, the response returns the default sample response data.

Add custom examples

In the actual test process, the default sample response data may not meet the requirements, you can add a custom example, according to the increase of request parameters to determine which example to use, for example, now add an example:

Added the name parameter and different response data for this sample response:

Then go back to the GET request and add the name parameter:

Make a request, you can see that the get request now goes to the newly created example instead of the default one, which is based on the newly added parameter. If the URL matches the parameter, it will go to the corresponding example.

Mock history

Back to the Mock Server panel:

You can see the Mock Server historical request record.

Click on any record to see the detailed data of the request and response:

conclusion

Postman Mock Server is a Mock Server that can be used as a Mock Server.

Whether you’re a front end or back end user, if you have a Mock requirement and your company doesn’t have a Mock process or specification, Postman is a simple, convenient way to implement a Mock Server without having to write any code.

Well, today’s share to this, I will continue to share more interesting development technology, follow the public number Java technology stack first push.

You have more fun things, also welcome to share!

Pay attention to me, don’t get lost!

Copyright statement: this article is the public number “Java technology stack “original, original is not easy, reprint, quoting the content of this article please indicate the source, prohibit copying, washing manuscript, please respect, respect everyone’s labor and intellectual property rights, plagiarism will be corrected.

Recent hot articles recommended:

1.1,000+ Java interview questions and answers (the latest version of 2021)

2. Finally got the IntelliJ IDEA activation code through the open source project, how sweet!

3. Ali Mock tool officially open source, kill all the Mock tools on the market!

4.Spring Cloud 2020.0.0 is officially released, a new and disruptive version!

5. “Java Development Manual (Songshan version)” the latest release, speed download!

Feel good, don’t forget to click “like” + forward oh!