What are API test cases?
In today’s Internet era, as a programmer of e-commerce platform, he must often deal with HTTP API. A common situation is API testing. Apart from what can be replaced by unit testing, it is often necessary to actually send HTTP requests. These things that are responsible for making HTTP requests may be one line
curlCommand, it could be a
.jsFiles can also be an operation of clicking a button in postman, but no matter what the form, they are API test cases. Although the name has the word “use case”, it is often checked by people. Use cases pay more attention to the HTTP request.
Why manage them?
Unlike thousands of ordinary HTTP (or HTTPS) requests generated in the browser every day, API test cases are worth careful management, because:
- API test cases are often reused, so they must be persisted. Maybe it is saved as shell script, maybe it is saved as script language source file, maybe it is saved as data file of a certain software;
- Test cases need to be written for multiple APIs, so test cases corresponding to different APIs must be distinguished. For example, a service that is responsible for managing business resources (such as a service that manages commodity data and provides restful API) should at least provide the function of adding, deleting, checking and modifying, and then there should be corresponding API test cases for adding, deleting, checking and modifying;
- It is necessary to write use cases for API of multiple services, so it is necessary to distinguish test case sets corresponding to different services. For example, since there are commodity services, there are probably order services, coupon services, logistics services, and so on. Each service has the function of adding, deleting, checking, and modifying. The APIs of these different services also need their own test cases;
- Different operating environments need to be distinguished. Usually, the local, development, testing and production environments are isolated from each other, and the parameters in one use case cannot be transferred to another environment.
The differences in the three dimensions of API, service, and environment make the number of test cases increase significantly. If you do not manage them, when you want to use them, you either have to write a script again from scratch, or you have to search for a long time to find the required use cases.
Using ORG – Mode management
What is org mode?
org-modeEmacs is an extension of Emacs editor, which enables users to take notes, maintain to-do items, arrange plans, and write documents in a fast and efficient text only way.
org-modeThe essence of Emacs lies in its ability to organize the outline and its ability to expand relying on Emacs, both of which make it competent to manage API test cases. One
.orgAn example of the file is shown in the figure below
How to use org mode to manage API test cases?
org-modeIt provides rich functions, but only manages API test cases. It doesn’t need too many fancy things. It just needs to
org-modeOutline and function of
org-babelThe characteristics are enough.
First, use different
.orgFiles distinguish between different environments.
Then, different levels of headers are used to distinguish different services, resource types, and APIs.
org-modeOfCode blockSyntax to write HTTP requests. By request
https://httpbin.org/uuidtake as an example
#+BEGIN_SRC restclient GET https://httpbin.org/uuid #+END_SRC
#+END_SRCOpen and end code blocks, respectively,
restclientThe code in this code block can be represented by Emacs
restclient-modeTo edit. In the code block,
GET https://httpbin.org/uuidRepresents a get method request
restclientAfter that, position the cursor over the code block and press
ctrl-c 'You can enter a separate buffer to edit the source code
Finally, if the
org-babel, or even directly on the code block
ctrl-c ctrl-cTo make an HTTP request.
As you can see, the content of the HTTP response will remain in this file
I have used other tools to manage API test cases before
- When I first worked, I used postman, which was a plug-in of chrome at that time;
- Later, out of love for the Firefox browser, I found a plug-in called restclient to replace postman. As time passed, I found that there was a big gap between the two, which could not be replaced after all;
- Then we met the problem in Emacs
restclient.elSo it took a long time for the pure
- Later, I began to work with Mac. I began to look for this kind of tool under Mac, and I met some problemsInsomnia. If someone asked me to recommend a GUI tool for HTTP API testing, I would recommend it without hesitation.
Later, I went back to Emacs and used it
org-modeTo manage these API test cases. This is the best way for me at the moment.
At the end of the paper.