Jmeter_Mock interface

First explain what a mock interface is.

Mock usually means that when testing an object, we construct some fake object to simulate the interaction with it. And the behavior of these Mock objects is what we set in advance and meets expectations. Use these Mock objects to test whether the object works normally under normal logic, abnormal logic or stress.

The biggest advantage of introducing Mock is that the behavior of Mock is fixed, which ensures that when you access a method of the Mock, you can always get an expected result that is returned directly without any logic. Mock interface is to use some reasonable means to construct objects to simulate the real interface to achieve the test effect we need. What are the test scenarios?

  The interface of the dependent upstream project has not been developed yet, and the downstream cannot conduct joint debugging, and it has been in a waiting state;

  The interface does not meet the current testing needs. Although the interface has been implemented, the individual fields/returns do not meet the test requirements;

Some common Mock methods:

  Write the simulation data directly in the code

  Intercept requests with JavaScript

  Use proxy tools such as Charles and Fiddler to intercept requests

  。。。。。。。

  etc

How to manage these Mock interfaces has become a problem. Fortunately, there are already many such platforms on the market, such as

Doclever

Rap2

Easy-Mock

Let's borrow a picture to illustrate the advantages of the Mock platform

From this picture, we can find that through the Mock platform, front-end and back-end parallel development can be achieved, and even testing can be involved. Can greatly improve work efficiency.

After a brief introduction to Mock, we can come to the actual operation. Here I have deployed a set of Easy-Mock platform locally , and the specific deployment process can be found on Github , or consult bloggers.

I created a Mock interface in the background to implement a simple responsive js, as shown in the figure below.

It probably means that a time parameter is passed in through the interface. The interface judges that if the parameter name is now, the interface returns the current time in real time. If the incoming parameter is id, the interface returns a random string. There is some mock syntax involved here. You can refer to the following documents

Easy Mock syntax description

Mockjs syntax description

Now you can go to the front desk to debug the interface

 

 After completing these tasks, you can write this interface to Jmeter for debugging, and you can see two different results.

We can also fill in the expected return value in the interface document into Mock to simulate the result, so that the interface test can get rid of the dependence on the environment and achieve real agility!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930523&siteId=291194637