There has been no mention of this two-day Debugtalk blog, wrote about the interface mock, previously felt that this implementation is particularly complex, see his blog to realize the simple can also, from yesterday to debug, according to the existing test environment logic wrote a feel very interesting to write a record, Later want to add to their own interface framework to go. Because the front-end business test will also be an interface response return to different front-end will have different processing logic (such as jump to different pages ah, what), previously may need to change the database or create the corresponding data, If the mock can be applied to the specific business can be implemented we can decouple the client and the server, the test will be more comprehensive.
The choice of flask also has 2 aspects to consider on the one hand can be a mock, on the other hand, it is very light also can quickly implement the Web (later test report display or interface script trigger can butt up), small and light things to start fast. To say these, directly mock the Code, as follows:
A simple description: I want to mock the login interface, Mobilelist is the analog database (can be understood as the user table), @app. Route () is a flask adorner, I understand is to match the interface a matching rule. The adorner-decorated function is the concrete return logic, where I had an understanding error yesterday, @app. Route ("/login/<int:uid>") This <int:uid> I just started to understand Requests.post (url,params) Inside the request parameters, and then run with postman request has been 404, was really a crash, and then looked at a lot of found this is the URL. "What's in front of it, except that the interface name is fixed in the app, it's not usually the case (I haven't seen it in my current test). The parameter methods represents the acceptable request method. The results of using postman validation are as follows:
This means that the call succeeded, which I have evolved, linked to the database, according to Mobile Query user table, when the length of 0 indicates that the user table does not exist, not 0 indicates existence and return UserID, the code is as follows:
Use the Postman validation results as shown in figure:
This is present in the user table and returns to UserID
This is not there, return-1. When I wrote again, I encountered two pits which were not resolved at present.
The first one is that I just wanted to put login into the class, but at the time of running I was always prompted for missing parameters, as shown in figure:
Another is the problem that cannot be invoked across packages, as shown in figure:
I can call the contents of the package Mockapi package, but the outer page and pagetest can not be invoked, not yet resolved, ready to study later, how and before the interface code fusion. In general, the reference article is as follows:
http://debugtalk.com/post/ApiTestEngine-0-setup-CI-test/
http://blog.csdn.net/yannanxiu/article/details/53116652