CN118152250A - Application programming interface test method, apparatus, device, medium and program product - Google Patents

Application programming interface test method, apparatus, device, medium and program product Download PDF

Info

Publication number
CN118152250A
CN118152250A CN202211518033.6A CN202211518033A CN118152250A CN 118152250 A CN118152250 A CN 118152250A CN 202211518033 A CN202211518033 A CN 202211518033A CN 118152250 A CN118152250 A CN 118152250A
Authority
CN
China
Prior art keywords
api
request
template
instance
call
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211518033.6A
Other languages
Chinese (zh)
Inventor
程红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Cloud Computing Technologies Co Ltd
Original Assignee
Huawei Cloud Computing Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Cloud Computing Technologies Co Ltd filed Critical Huawei Cloud Computing Technologies Co Ltd
Priority to CN202211518033.6A priority Critical patent/CN118152250A/en
Publication of CN118152250A publication Critical patent/CN118152250A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

Embodiments of the present application provide application programming interface testing methods, apparatus, devices, media, and program products. The method includes, in response to receiving an indication to call an API, obtaining a predefined template corresponding to the API based on keywords in the indication that identify the API, the predefined template including a request template for the API. The method further includes generating an instance value of the variable parameter based on a parameter baseline of the variable parameter in the request template, the parameter baseline describing a generation rule for the value of the variable parameter. The method also includes initiating a call to the API based on the request template and the generated instance value. Therefore, the written API test case can be decoupled from the running environment, higher-level abstract property and reusability of the test case are provided, the problem of automatic arrangement during execution under the condition of mutual dependence of APIs is solved, and the labor cost of API test and the probability of error introduction are obviously reduced.

Description

Application programming interface test method, apparatus, device, medium and program product
Technical Field
The present application relates to the field of information technology, and more particularly, to an application programming interface test method, an electronic device, a computer storage medium, and a program product.
Background
In software systems of Browser/Server (B/S) architecture and Client/Server (C/S) architecture, client-Server interactions are often performed through application programming interfaces (Application Programing Interface, APIs) provided by the Server. The client may send a request to the server for a certain API (e.g., according to the protocol HTTP, etc.) to call the API. The server executes the corresponding API according to the received request and returns the result as a response to the client. To ensure availability, etc. of APIs, a great deal of testing of these API interfaces is required before they are released.
Disclosure of Invention
The embodiment of the application provides an API test scheme.
In a first aspect, an API testing method is provided. The method comprises the following steps: in response to receiving an indication to call an API, acquiring a predefined template corresponding to the API based on keywords in the indication identifying the API, wherein the predefined template comprises a request template for the API; generating an instance value of the variable parameter based on a parameter baseline of the variable parameter in the request template, the parameter baseline describing a generation rule of the value of the variable parameter; and initiating a call of the API based on the request template and the instance value. In this way, calls to APIs can be made simply indicated by action words, and content in a call request that depends on the instance environment can be automatically generated upon execution according to the generation rules. Therefore, the call to the API can be decoupled from the instance context such as the API deployment address, the running environment setting and the like, and can be executed and reused in various environments only by writing once, thereby obviously reducing the cost required for writing the API test case.
In some embodiments of the first aspect, wherein generating an instance value of the variable parameter based on a parameter baseline of the variable parameter in the request template comprises: acquiring indicated context information; and generating an instance value based on the context information and the parameter baseline. In this manner, instances of parameters may be automatically generated in a manner consistent with, for example, context information.
In some embodiments of the first aspect, initiating the call of the API comprises: generating an instance request for the API based on the request template and the instance value; and sending the instance request to the API. In this manner, call requests to APIs that meet the current execution indication may be automatically generated and issued.
In some embodiments of the first aspect, the predefined template further comprises an output template comprising conversion rules that convert the API's response to the instance request to another structure, and the method further comprises: receiving an instance response of the API to the instance request; and converting the instance response to an instance output of the execution indication based on the output template. In this manner, useful information in API responses derived based on executing action words can be automatically extracted and processed, thereby enabling more concise and easier analysis and processing of execution results.
In some embodiments of the first aspect, the API is a first API, the keyword is a first keyword, and a reference to a second API is also included in the request template, the reference being identified by a second keyword corresponding to the second API. Thus, the dependency relationship between APIs can be expressed in the request template of the APIs in a concise manner, and a foundation is provided for automatically arranging and executing the test of the APIs.
In some embodiments of the first aspect, the method further comprises detecting whether a loop exists in a reference graph of an API associated with the request template; and if no loop exists in the reference graph, determining to initiate the call of the API. In this way, the existence of the API execution loop dependency can be automatically detected, so that system crashes or unlimited calls caused by the loop dependency in executing the API call are avoided, and the labor cost for maintaining the dependency between the APIs can be saved.
In some embodiments of the first aspect, detecting whether a loop exists in a reference graph of an API associated with the request template comprises: determining a reference graph by recursively parsing references to the APIs in the request template identified by the keywords; and if a loop is detected to exist in the reference graph during the determination of the reference graph, buffering the detected loop for subsequent detection. In this way, an efficient way of automatically detecting the presence of cyclic dependencies between APIs and a method of improving efficiency in detection is provided.
In some embodiments of the first aspect, the parameter baseline includes a reference to other variable parameters, and the method further comprises: it is detected whether a loop exists in the parameter reference graph associated with executing a call to the API. In this way, circular dependencies between parameters can be automatically detected and system crashes or unrestricted calls during execution of API calls that may result therefrom can be avoided.
In some embodiments of the first aspect, the predefined template is a first predefined template, the request template is a first request template, the variable parameter is a first variable parameter, the instance value is a first instance value, the call is a first call, and generating the instance request comprises: acquiring a second predefined template corresponding to a second API based on the second keyword, wherein the second predefined template comprises a second request template aiming at the second API; generating a second instance value of a second variable parameter based on a parameter baseline of the second variable parameter in a second request template; and initiating a second call of a second API based on the second request template and the second instance value; and generating an instance request based on the request template, the first instance value, and the second call. Thus, the method for automatically arranging and executing the multiple API calls associated with the current execution task is provided, so that the labor cost for arranging the API test can be saved, and the test efficiency can be improved.
In some embodiments of the first aspect, the method further comprises: creating an execution stack based on the request template, the execution stack indicating a calling order of the plurality of APIs that are called as a result of executing the first call; and clearing resources created by calling the plurality of APIs during the first call in an order opposite to the calling order. Therefore, the resources of the API call can be automatically cleaned in proper sequence, and the efficiency of the API test is further improved.
In some embodiments of the first aspect, the method further comprises: a visualization of calls to the execution API is generated, wherein the visualization includes a call chain of the plurality of API calls caused by the call and call states of each of the plurality of APIs in the call chain. In this way, the execution condition of the API call and the positioning of the problems in execution can be more intuitively shown, so that the analysis of the API test is easier.
In some embodiments of the first aspect, the method further comprises: generating a third instance value of the variable parameter based on the parameter baseline in response to receiving a second indication to call the API, the API identified by the keyword in the second indication; and initiating a third call of the API based on the request template and the third instance value. In this way, the test call to the API can be automatically adjusted and initiated based on various contexts such as the API actual running setting and account, so that the test case to the API deployed in one environment can automatically adapt to multiple environments, and the reusability of the test is significantly improved.
In a second aspect, an apparatus for API testing is provided. The device comprises an acquisition module, a generation module and an initiation module. The acquisition module is configured to: in response to receiving an indication to call an API, a predefined template corresponding to the API is obtained based on keywords in the indication that identify the API, the predefined template comprising a request template for the API. The generation module is configured to: an instance value of the variable parameter is generated based on a parameter baseline of the variable parameter in the request template, the parameter baseline describing a generation rule of the value of the variable parameter. The initiation module is configured to: based on the request template and the instance value, a call to the API is initiated.
In some embodiments of the second aspect, the generating module comprises: a context acquisition module configured to acquire indicated context information; and an instance value generation module configured to generate an instance value based on the context information and the parameter baseline.
In some embodiments of the second aspect, the initiating module comprises: a request generation module configured to generate an instance request for the API based on the request template and the instance value; and a request sending module configured to send the instance request to the API.
In some embodiments of the second aspect, the predefined templates further comprise output templates comprising conversion rules that convert the API's response to the instance request to another structure, and the apparatus further comprises: a response receiving module configured to receive an instance response of the API to the instance request; and a conversion module configured to convert the instance response into an instance output of the execution indication based on the output template.
In some embodiments of the second aspect, the API is a first API, the keyword is a first keyword, and a reference to a second API is also included in the request template, the reference being identified by a second keyword corresponding to the second API.
In some embodiments of the second aspect, the apparatus further comprises: a loop detection module configured to detect whether a loop exists in a reference graph of an API associated with the request template; and an initiation determination module configured to determine to initiate a call to the API if no loop exists in the reference map.
In some embodiments of the second aspect, the loop detection module comprises: a reference parsing module configured to determine a reference map by recursively parsing references to the APIs in the request template identified by the keywords; and a loop caching module configured to cache the detected loop for subsequent detection if a loop is detected to exist in the reference graph during the determination of the reference graph.
In some embodiments of the second aspect, the parameter baseline includes references to other variable parameters, and the apparatus further includes a parameter loop detection module configured to detect whether a loop exists in the parameter reference graph associated with executing the call of the API.
In some embodiments of the second aspect, the predefined template is a first predefined template, the request template is a first request template, the variable parameter is a first variable parameter, the instance value is a first instance value, the call is a first call, and the request generation module comprises: a second obtaining module configured to obtain a second predefined template corresponding to a second API based on a second keyword, the second predefined template including a second request template for the second API; a second instance value generation module configured to generate a second instance value of a second variable parameter based on a parameter baseline of the second variable parameter in a second request template; a second initiation module configured to initiate a second call of a second API based on a second request template and a second instance value; and a dependent request generation module configured to generate an instance request based on the request template, the first instance value, and the second call.
In some embodiments of the second aspect, the apparatus further comprises: an execution stack creation module configured to create an execution stack based on the request template, the execution stack indicating a calling order of the plurality of APIs that are called as a result of executing the first call; and a resource purging module configured to purge resources created by calling the plurality of APIs during the first call in an order reverse to the calling order.
In some embodiments of the second aspect, the apparatus further comprises a visualization module configured to: a visualization of calls to the execution API is generated, wherein the visualization includes a call chain of a plurality of API calls caused by the call and call states of each of the plurality of APIs in the call chain.
In some embodiments of the second aspect, the generation module is further configured to: generating a third instance value of the variable parameter based on the parameter baseline in response to receiving a second indication to call the API, the API identified by the keyword in the second indication; and the initiation module is further configured to: a third call of the API is initiated based on the request template and the third instance value.
In a third aspect, an electronic device is provided. The electronic device comprises a processor and a memory having stored thereon computer instructions which, when executed by the processor, cause the electronic device to perform the actions of the method according to the first aspect or any embodiment thereof described above.
In a fourth aspect, a cluster of computing devices is provided, the cluster of computing devices comprising at least one computing device, each computing device comprising a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform operations according to the method in the first aspect described above or any embodiment thereof.
In a fifth aspect, a computer-readable storage medium is provided. The computer-readable storage medium has stored thereon computer-executable instructions which, when executed by a processor, implement operations according to the method of the first aspect described above or any embodiment thereof.
In a sixth aspect, a computer program or computer program product is provided. The computer program or computer program product is tangibly stored on a computer-readable medium and comprises computer-executable instructions which, when executed, implement operations in accordance with the method in the first aspect or any embodiment thereof described above.
Drawings
The above and other features, advantages and aspects of embodiments of the present application will become more apparent by reference to the following detailed description when taken in conjunction with the accompanying drawings. In the drawings, wherein like or similar reference numerals denote like or similar elements, in which:
FIG. 1 illustrates a schematic diagram of an example environment in which various embodiments of the present disclosure may be implemented;
FIG. 2 illustrates an example method flow diagram for API testing in accordance with some embodiments of the present disclosure;
FIG. 3 illustrates an example showing an example execution stack created during execution of an example action word, according to an embodiment of the present disclosure;
FIG. 4 illustrates an example schematic diagram of a resource cleanup sequence corresponding to the example of FIG. 3;
FIG. 5 illustrates an example citation diagram of action words in which loops exist, according to some embodiments of the present disclosure;
FIG. 6 illustrates an example visualization of task execution that may be generated in accordance with some embodiments of the present disclosure;
FIG. 7 illustrates an example schematic diagram reflecting the order of execution of elements in an action word execution process according to an embodiment of the disclosure; and
FIG. 8 illustrates an example visualization of an API call chain that may be generated in accordance with some embodiments of the present disclosure;
FIG. 9 illustrates a schematic block diagram of an apparatus for API testing in accordance with some embodiments of the present disclosure;
FIG. 10 shows a schematic block diagram of an example device that may be used to implement embodiments of the present disclosure;
FIG. 11 illustrates a schematic block diagram of an example cluster of computing devices that may be used to implement embodiments of the disclosure; and
FIG. 12 illustrates a schematic block diagram of an example implementation of a cluster of computing devices that may be used to implement embodiments of the disclosure.
Detailed Description
Embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While the application is susceptible of embodiment in the drawings, it is to be understood that the application may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided to provide a more thorough and complete understanding of the application. It should be understood that the drawings and embodiments of the application are for illustration purposes only and are not intended to limit the scope of the present application.
In describing embodiments of the present application, the term "comprising" and its like should be taken to be open-ended, i.e., including, but not limited to. The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first," "second," and the like, may refer to different or the same object. Other explicit and implicit definitions are also possible below.
To ensure availability and validity of APIs, etc., a large number of test calls to these API interfaces and analysis of the response results are required before the APIs are released. In conventional API testing methods, test cases are mainly written manually or generated separately for deployed API instances by means of semi-automatic tools. In these methods, the test cases are highly coupled to the deployment environment of the API, and for the same API deployed in different environments (e.g., on different servers), a set of test-invoked cases and corresponding test response parsing code needs to be generated for each environment to accommodate the differences in the operating environments. There are a number of duplicate codes and loose bomb modifications in these test cases.
Furthermore, in conventional API testing, when an API has a dependency (e.g., parameters of one API depend on response information to a request from another API), a significant amount of labor is required to orchestrate and maintain dependencies between APIs. First, the execution order of API test cases where dependencies exist requires manual orchestration. When the API involves resource creation, a corresponding resource clean-up step is also required to be manually orchestrated. Second, for multiple test cases that rely on the same API, the relevant test code of the relied API needs to be rewritten for each test case. When the dependent API changes, all test cases that depend on it need to be modified. These problems with respect to API testing present human and resource consumption and are prone to introducing errors, which present challenges for the writing and maintenance of API test cases.
To solve the above-described problems, as well as others, the present disclosure provides a solution for API testing. The scheme encapsulates an API into an abstract word that is identified by, for example, a keyword that reflects the name of the corresponding API (e.g., as the name of the abstract word), and is associated with a predefined request template for the API. In embodiments of the present disclosure, the names of such abstract words often reflect the actions that the corresponding API is expected to perform. The abstract words of such an encapsulation API are also referred to hereinafter as Action Words (AW). For brevity, the keyword identification of an action may also be referred to below simply as an action.
Parameters that are variable between instance requests of the action word encapsulated API (e.g., URL of server where the requested API is actually deployed, etc.) are defined as parameters of the action word. These parameters have an associated parameter baseline that indicates how the actual parameter values should be generated when the action word is executed. The user may perform a test call to the API simply by instructing execution of the corresponding action word, and the parameters for each execution may be automatically generated based on the indicated context information (e.g., the user account from which the indication was issued, the API deployment URL associated therewith, etc.). In some embodiments, the action words may also be associated with a unified response body template. On this basis, useful information in the API response obtained based on execution of the abstract word can be automatically extracted and processed, thereby providing a more concise and effective output.
In addition, in some embodiments of the present disclosure, references to other action words are also included in the request templates to which the action words correspond. When writing a new API test based on action words, other API calls that the test depends on can be introduced by referencing other action words without having to repeatedly write related requests and result parsing code of the dependent API. Also, by recursively parsing the references of the action words as such action words are executed, multiple API calls associated with the current execution task and subsequent resource cleanup may be automatically orchestrated and executed. Some embodiments of the present disclosure also graphically relate the testing process of the API based on the execution of action words, making the API test results easier to analyze.
By using the method disclosed by the invention, the written API test case can be decoupled from the running environment, higher level abstract property and reusability of the test case are provided, and the problem of automatic arrangement when executing under the condition of mutual dependence of APIs is solved. In this way, the labor and the probability of introducing errors required to write, execute, and analyze API test cases can be significantly reduced.
FIG. 1 illustrates a schematic diagram of an example environment 100 in which various embodiments of the present disclosure may be implemented. As shown in FIG. 1, the example environment 100 includes a server 110, with APIs 120-1, APIs 120-2, …, and APIs 120-N disposed on the server 110. For convenience of the following description, APIs 120-1, 120-2, …, and 120-N are collectively or individually referred to as APIs 120 in embodiments of the present disclosure. The server may receive a request for the API 120 from a client or browser on the user device, perform a server-side process corresponding to the request, and return a response to the request to the requesting user device.
Also included in environment 110 is computing device 130. In some embodiments, the user device 120 may be implemented as an electronic device such as a personal computer, smart phone, tablet computer, or the like. The computing device 130 may be in communication with the server 110. For example, the computing device 120 may send a request for the API 120 as a client to the server 110, receive a corresponding response from the server 110, and parse and otherwise process the response.
It should be understood that embodiments of the present disclosure are not limited in the manner of communication, such as communication in a wired or wireless manner. The wired means may include, but are not limited to, fiber optic connections, universal serial bus connections, etc., and the wireless means may include, but is not limited to, mobile communication technologies (including, but not limited to, cellular mobile communications, etc., wi-Fi, bluetooth, point-to-point, etc.).
An action thesaurus 140 may be included on the computing device 120. The action word library 140 may include definitions for a plurality of action words written in accordance with embodiments of the present disclosure. The definition of an action word may include its identifying keyword, an associated predefined template, and so on. For example, the computing device 120 may implement parsing and execution of action words in the action thesaurus 140, etc. functions to perform testing for the API 120, according to embodiments of the present disclosure.
Further, although shown separate from computing device 130 for clarity of illustration, server 110 is depicted. In some embodiments, however, the server 110 may also be hosted on the computing device 130, such as in a portion of an API test scenario. For example, the computing device 130 may run the server 110 with the APIs 120 deployed locally and also simulate the behavior of clients to conduct various tests on the local APIs 120 before these APIs 120 are formally published. Furthermore, although shown as a single device, computing device 130 may be implemented in any other form suitable for performing the respective functions, such as being implemented as multiple distributed devices and/or virtual devices deployed in the cloud, and so forth.
It should be understood that the architecture and functionality in the example environment 100 are described for illustrative purposes only and are not meant to suggest any limitation as to the scope of the disclosure. Also, other devices, systems, or components, etc., not shown, may also be present in the example environment 100. For example, computing device 130 may also call other APIs running on other servers. For example, computing device 130 may provide services according to embodiments of the present disclosure and receive an indication from other user devices to perform, for example, an API test. In addition, embodiments of the present disclosure may also be applied in other environments having different structures and/or functions.
Fig. 2 illustrates a flow chart of an API test example method 200 according to some embodiments of the present disclosure. The example method 200 may be performed, for example, by the computing device 130 shown in fig. 1. It should be appreciated that method 200 may also include additional actions not shown, the scope of the present disclosure being not limited in this respect. The method 200 is described in detail below in connection with the example environment 100 of fig. 1.
In response to receiving an indication to call an API, a predefined template corresponding to the API is obtained based on keywords in the indication that identify the API, at block 210. The predefined template includes a request template for the API. For example, the computing device 130 may, in response to receiving an indication to call the API 120, retrieve a predefined template corresponding to the API 120 based on keywords in the indication that identify the API 120 (e.g., from the action library 140).
In some embodiments, the computing device 130 may receive the indication from its own graphical user interface or from a user device. For example, the computing device 130 may provide a list of action words that it is capable of processing to the action word library 140 so that a user may select an action word name corresponding to an API that is desired to be tested from the provided list of available action words to instruct the computing device 130 to call the API. In some embodiments, the computing device 130 may also receive such an indication via other means, provided that keywords identifying the API and associated predefined templates are included in the indication. The computing device 130 may then determine (e.g., in its action thesaurus) an associated predefined template based on the keyword. Moreover, the indication of execution of a certain action word may also be caused by the execution of other action words that reference the action word, as will be described in more detail below.
At block 220, instance values for the variable parameters are generated based on the parameter baselines for the variable parameters in the request template. The action word's request template describes the structure of the request message for the associated API. Wherein the common content in the different instance request messages for the API is fixed in the template and the possible variations between the different instance requests are defined as variable parameters in the template. These parameters are associated with a parameter baseline that describes the generation rules of the instance values of the respective parameters.
During subsequent execution of an API call by computing device 130 based on the action word, the rules included in these parameter baselines will be used to generate corresponding parameter instance values as input to the call. For example, computing device 130 may generate instance values for the variable parameters based on parameter baselines for the variable parameters in a request template associated with API 120 (as described in connection with block 210). The generation of parameter baselines and instance values will be described in more detail later in connection with table 1.
In some embodiments, references to one or more other action words are also included in the request template encapsulated by the action word. Similarly, these other action words encapsulate other corresponding APIs, and the reference may be identified by keywords (e.g., names of other action words) corresponding to the encapsulated APIs. These keywords can each uniquely identify an action word. The reference indicates the dependencies of the API encapsulated by the action word on other APIs. In the course of the computing device 130 performing an API call based on the action word, a call result with other APIs that are relied upon is required as input. The reference to an action word will be described in more detail later.
At block 230, a call to the API is initiated based on the request template and the instance value. For example, the computing device 130 may initiate a call to the API 120 based on the request template for the API 120 obtained at block 210 and the parameter instance value generated at block 220. In some embodiments, to perform the call, computing device 130 may generate an instance request based on the request template and the instance value, for example, by assigning the instance value to the corresponding parameter. The computing device 130 may then send the generated instance request for the API 120 (also potentially described herein as sending instance requests to the API), e.g., for testing the API, etc.
In testing for APIs, the same API typically needs to be called multiple times and in some cases in different runtime environments. When in some embodiments, in response to receiving another indication identified by the action word to call the same API 120, the computing device 130 may generate another set of instance values for the variable parameters of the API 120 based on the relevant parameter baseline and initiate another call to the API 120 based on the request template and the another set of instance values using the methods described above with respect to method 200. Thus, the action word encapsulated API request may be reused multiple times.
Using the method 200, an API can be packaged into action words, and content in instance calls to the API that depends on the execution environment and other instance contexts can be abstracted into variable parameters of the action words. In this way, content in an API call that depends on the instance environment may be automatically generated upon execution according to the generation rules. Therefore, the call to the API can be decoupled from the instance context, and the call can be executed and reused in various running environments only by writing once, so that the cost for writing the API test case is obviously reduced.
An example definition template of an action word as described above and an API example corresponding to the action word are shown in table 1. It should be understood that the specific syntax format in table 1 is by way of example only, and that other formats of implementation may exist. In the non-limiting example of table 1, the target API is used to create a subnet of the virtual private cloud (Virtual Private Cloud, VPC) of version V2.0. The name "create_subscriber_v2_vpc" of an action word is used as a key word or identifier for identifying the action word or the corresponding API. For example, the user may use the name to indicate an API that needs to be called (e.g., tested). When such an indication is received by computing device 130, the corresponding template may be located for further processing based on the name.
Table 1: action words correspond to examples of APIs
The action word template comprises a request template aiming at the API, wherein the request template comprises a URL and a template of a request body, and the URL and the request body are required to be sent to. In the request template, fields that depend on the instance context are abstracted as parameters. For example, because APIs may be deployed at different ENDPOINTs and deployment on these different ENDPOINTs all need to be invoked for testing, the ENDPOINT URLs within the URLs in the templates are abstracted into the parameter "GLOBAL. VPC_ENDPOINT". Similarly, the request body template of FIG. 1 also includes therein; another variable parameter is "global. Auto_check_name". This means that these parameters are generated each time a word is executed and may differ at each call due to various relevant context changes of the running environment, number of call executions, etc.
By way of illustration, the rightmost column of Table 1 shows an example of an API call generated in one execution of the action word. In this example, the parameter "global.vpc_endipoint" is assigned an address (here exemplified by "sample.com") where the actually requested API is deployed. In addition, the parameter "global. Auto_check_name" is also assigned the instance value "auto_check_ nhls23jc56".
It should be appreciated that in the example syntax implementation, the names of the variable parameters are indicated by pairs of brackets "< >", but that in other implementations other syntax variations and other representation formats may also exist. In addition, a reference "get_next_ DETAIL _vpc.id" to another action word is also included in the example template, which will be described in more detail later.
To enable computing device 130 to automatically generate example values for these variable parameters. A parameter baseline for the variable parameter is defined. The parameter baseline describes what rules the instance value of the corresponding parameter (e.g., identified by the parameter name) should be generated in one execution of the action word. Thus, the computing device 130 may, for example, at the beginning of a test task, obtain an associated predefined template based on action words to be performed in the test task, and further generate instance values from parameter baselines of parameters therein, assign instance values to the respective parameters, thereby instantiating API requests in the task.
In some embodiments, the parameter baseline may define a source of parameter values. For example, the instance value of the parameter may be a constant, a random value, an enumerated value, or the like. The parameter base line may also define the type of parameter value, which may be, for example, boolean, integer, decimal, common string, encrypted string, etc.
The generation rules for the parameter instance values are typically related to context information for the current execution indication, which may include, for example, an API deployment platform, operating environment parameters, current execution sequence number, and the user account from which the indication was issued, among others. The computing device 130 may obtain the indicated context information and the context information and parameter baseline to generate instance values for execution.
In some embodiments, the parameter baseline may define that the parameter is a preset parameter associated with a currently logged-in user account, site, and common name, etc. For example, the instance value of the parameter is fixed for the determined account or selected site. Upon execution of the actual call, for such parameter baseline, computing device 130 may obtain context information for an account or the like associated with the current execution to generate a corresponding parameter value.
In some embodiments, the parameter baseline may define that the parameter belongs to a custom parameter. Such parameter instance values may vary from instance to instance with some set value of the current user (e.g., number acquired or saved by computing device 130 based on configuration interface inputs, etc.) and operation in the rules. In performing an actual call, for such parameter baselines, computing device 130 may obtain contextual information about the current settings, etc., and determine corresponding parameter values based on the information and other rules of the baseline description.
In some embodiments, the parameter baseline may also define more complex rules, including combinations of the example rules described above with other rules. For example, computing device 130 may increment an instance value of a numeric parameter with each invocation based on the definition of the parameter baseline. For example, computing device 130 may also generate an instance value of a string parameter as a fixed string depending on the current account, plus a randomly generated suffix, based on the definition of the parameter baseline. It should be understood that the above-described baselines are by way of example only, and that other generation rules are possible.
In some embodiments, the parameter baseline for one parameter may use other one or more parameters. For example, a parameter baseline for parameter "REGION_ENDPOINT" may define that the instance value of the parameter is determined by the combination of instance values for parameters "REGION. CODE" and "GLOBAL_ENDPOINT" in the same call. In such an embodiment, computing device 130, when generating an instance value of a parameter, will first generate instance values of other parameters that need to be used in its parameter baseline. Computing device 130 will generate instance values for other parameters based on the parameter baselines for those other parameters. It should be appreciated that if instance value generation of other parameters requires further generation of instance values of additional parameters, computing device 130 will first generate instance values of additional parameters. By so doing, the computing device 130 may recursively automatically generate all parameter values needed to execute the current call to instantiate the API that needs to be executed.
The requests for different APIs may have the same variable parameters, e.g., requests for both APIs require some information associated with the account. Thus, the parameter baseline may exist independent of the action word, and the same parameter may be included in different action word definitions. For example, computing device 130 may store or otherwise associate a defined parameter baseline, and may display to the user the parameters for which it may identify and generate instances. Thus, these parameter baselines can be used directly by writing parameter names to templates, without being defined again, when writing new action words.
In some embodiments, an output template is also included in the predefined template corresponding to the API, the output template including conversion rules for converting the API's response to the instance request into another structure, i.e., the conversion rules define how the conversion should be performed for such a response. In such embodiments, after generating and sending an instance request for an API as described above, computing device 130 may receive an instance response to the instance request from the API. The computing device 130 may then convert the instance response to an instance output of the execution action word based on the output template.
The "action word template" column of table 2 shows an example output template of the action word "create_action_v2_vpc" in table 1. The example template specifies the following conversion rules: an instance response received by executing "create_subnet_v2_vpc" using the method as described above will be converted into an output including the "SUBNET" data object. The "subnet" has an "id" field and a "name" field, where the value of the "id" field should be extracted from the "id" field of the instance response and the value of the "name" field should be extracted from the "name" field of the instance response.
Table 2: example output template for action words
According to the template, computing device 130 may perform transformations for the example responses as shown in the "API examples" column of Table 2, generating outputs as shown in Table 3.
Table 3: example output of action words
As can be seen from tables 2 and 3, the outputs in table 3 include more concise content than the original responses. In the response content of an API, more less relevant information is typically included in addition to the part of interest in the call. By using the output templates by the computing device to further refine and convert the responses therein to generate output, execution results that are easier to analyze and process may be provided.
In some embodiments, the output template may include an expected response code for execution, e.g., "200OK" for HTTP. Upon receiving an instance response corresponding to the sent instance request, computing device 130 first determines whether the actual response code in the response is consistent with the expected response code. For example, there may be a request template for which the expected response is unsuccessful for testing purposes. In such embodiments, the computing device 130 may perform further information extraction and processing only if the actual response code is consistent with the expected response code, or include a corresponding error hint in the output if the response code is inconsistent.
In some embodiments, preset symbols may be included in the output template. For example, < NULL >, < not_null >, < BLANK >, < not_null >, < EMPTY >, and < not_empty >, etc. These preset symbols may indicate that the computing device generates some content of the output for the state of some portion of the response. For example, the computing device 130 may perform data extraction based on the conversion rules described in the output template using preset symbols, when certain fields in the response are not empty. For example, the computing device 130 may perform the corresponding conversion by outputting the null value of the particular field to some default value according to the conversion rule described in the output template using the preset symbol.
In some embodiments, extraction rules for the output of asynchronous responses may be included in the output template. For example, the computing device 130 may extract the corresponding field after the response state becomes expected in the asynchronous call according to rules in the output template.
In some embodiments, various operators may be included in the output template, and the computing device may perform various operations in generating the output according to the transformation rules described by the operators. For example, the computing device 130 may filter, sort, and value the array according to the output template, compare the values, parse a field in a predetermined manner, and so forth. For example, the computing device 130 may sort the array extracted from the response as an output field according to a template. For example, the computing device 130 may make assertion decisions regarding various states in the response content, as well as the results of the operations described above, and use the assertion decisions as output fields or as a basis for further generation of the output fields.
In some embodiments, the various elements in the templates described above may be written by predefined grammatical implementations. Computing device 130 may correspondingly implement the functionality to parse and execute the various templates so written so as to be able to respond from the instance of the request to executing the output of the action word. In some embodiments, based on the template grammar implementation, computing device 130 may also provide auxiliary functionality to write action-word based API test cases.
As previously described with respect to method 200, a reference to another API is also included in the request template associated with the API, the reference identified by a keyword corresponding to the other API. For example, refer again to table 1. In the request template in table 1, there is a reference "get_network_ DETAIL _vpc.id" at the value of the field "network_id". The reference indicates that when an instance request for the API encapsulated by the action word "CREATE_SUBNET_V2_VPC" is generated during execution of the action word, the instance value of "network_id" in the request should use the value of "ID" field in the output of the execution action word "GET_NETWORK_ DETAIL _VPC". In embodiments in which the predefined template of the referenced action word includes an output template, the field may be a field in the output of the computing device 130 after performing the conversion of the original response to perform the action word based on the output template.
In such an embodiment, when computing device 130 executes a certain action word to generate an instance request for a corresponding API, the following two are required as inputs: an instance value generated based on a parameter baseline of the parameter of the action word, and an execution output of other action words referenced by the action word. On the other hand, the output of the action word may be used as an execution input of another action word referring to the action word.
In embodiments where the currently executed action word references another action word, the computing device 130, when executing the action word, may parse the action word to reference another action word (e.g., by declaring the name of the action word). Then, similar to that described above with respect to method 200, computing device 130 may first initiate a call to the referenced action word in a manner similar to that described above with respect to method 200.
The computing device 130 may obtain a predefined template of the API of the referenced action word package based on the referenced action word and generate an instance value of the referenced action word based on a parameter baseline of the variable parameter in the predefined template. Computing device 130 may then generate and request an instance based on the instance value and the request template of the referenced action word to invoke the API of the referenced action word package.
On this basis, computing device 130 may generate an instance request for the current action word based on the currently executed action word request template, the parameter instance values for the current action word, and the above-described call to the API of the referenced action word package. Taking the execution of "create_subsumet_v2_vpc" in table 1 as an example, the computing device 130 will first instantiate and execute the action word "get_network_ DETAIL _vpc" that it references. After taking the output of the execution "get_network_ DETAIL _vpc", the computing device 130 assigns the value of the "ID" field in the output to "network_id" in the request template of "create_subscriber_v2_vpc" and assigns the instance value of the parameter baseline generation to the corresponding parameter. Whereby requests for APIs encapsulated by "create_subnet_v2_vpc" can be instantiated.
It should be understood that one API may depend on multiple APIs, and that the dependent APIs may also depend on other APIs as well. Thus, one action word may reference a plurality of other action words, and the referenced action word may further reference additional action words. In such embodiments, when generating and initiating a call to an API by executing an action word, the computing device 130 may recursively parse the action word reference relationship and execute the action word that needs to be executed due to the reference. In this way, computing device 130 may enable automatic orchestration and execution of API calls.
On this basis, computing device 130 may also enable automatic creation and cleaning of resources. Other APIs often need to be called to create some resources during the call of an API. Subsequently, the created resources need to be cleaned up. API calls for creation and cleaning of certain resources may be written in pairs and packaged into corresponding action words. These action words may be included by reference in templates of action words written for other API calls, and thus referenced by the action words.
In such embodiments, during execution of an action word, the computing device 130 may create an execution stack based on the recursive parsing of the request template described above that indicates a call order of a plurality of APIs that were recursively invoked as a result of executing the current call, wherein each call is identified by a respective action word name. The example 300 in fig. 3 illustrates an example execution stack 320 created during execution of the example action word 310, which example execution stack 320 may be created, for example, by the computing device 130 of fig. 1.
During execution, computing device 130 instantiates a request for a corresponding API to make a call based on request template 330 of action word 310. When instantiation proceeds to action word 311 referenced in the template, computing device 130 will first execute action word 311 to obtain an output to assign a value to field 340 in request template 330. And, computing device 130 records the action word in execution stack 320, as shown by entry 321. Similarly, computing device 130 executes the next referenced action word 312 and records the execution in entry 322.
Computing device 130 then proceeds to execute to referenced action word 314. In executing the action word 314, the computing device 130 detects that the action word 314 references another action word in turn according to the request template associated with the action word 314. Thus, computing device 130 first executes the action word referenced by action word 314 and stores the execution in entry 323. In particular, in this example, the action word execution corresponding to entry 323 relates to the creation of a resource, and this information may also be in an item in entry 323. Next, the computing device may execute action word 314 using the result of the execution corresponding to entry 323 and store the execution in entry 324. Continuing in this manner, computing device 130 will continue to execute the action word that needs to be invoked due to the reference until action word 310 itself can be executed, and that execution can be stored in the last entry 332 of the execution stack.
In some embodiments, the action words of the encapsulation API may be defined as repeatable and non-repeatable. The computing device 130 may monitor the action word execution involved in one execution and ensure that non-repeatable action words are executed only once during this time. For example, the computing device may identify the action word that created the resource as non-repeatable. In this way, resource creation may be minimized, thereby optimizing resource usage.
On this basis, the computing device 130 may utilize the execution stack to automatically clean up resources created during the task, whether or not execution was successful. In such embodiments, computing device 130 may purge resources created during the entire call in an order that is opposite to the order of calls indicated by the execution stack. In the example of fig. 3, the order of execution of the action words is indicated by the bottom-up (i.e., starting from the top-of-the-first entry) entry of the execution stack 320, a portion of which creates the resource. Correspondingly, computing device 130 may execute the resource cleaning actions corresponding to these entries according to an order that is reverse to the creation of the resources to clean up the relevant resources.
FIG. 4 illustrates an example schematic diagram 400 of a resource cleaning sequence corresponding to the example of FIG. 3. As shown in diagram 400, computing device 130 performs the cleaning of resources from top to bottom according to the entries in diagram 400 in reverse order to the order indicated by execution stack 320. First, computing device 130 executes a resource cleaning action corresponding to the execution recorded in entry 332, as shown in entry 432. The computing device then executes the resource cleaning actions corresponding to entries 329, 326, 325 and 323 in fig. 3, in turn, as shown by corresponding entries 429, 426, 425 and 423 in fig. 4. In this way, the created resource may be purged after it is created, thereby avoiding premature deletion while the resource is still dependent.
By performing tests for APIs based on API calls written using action words, computing device 130 may automate the process orchestration and execution of test tasks without human intervention during the process, thereby significantly improving the efficiency of the tests.
Since other action words may be referenced in the template of an action word, multiple APIs may be recursively invoked in executing the action word. If there is a loop in the call chain, then there is a circular dependency between these APIs. For example, FIG. 5 illustrates an example reference graph 500 of action words, where nodes represent action words, directed edges represent that there are references between connected action words and point to the referenced action words, according to some embodiments of the present disclosure. As shown in fig. 5, action word 540 references action word 550, action word 550 references action word 560, and action word 560 in turn references action word 540. These references make a circular dependency between the APIs of the three action word packages. Similarly, there is also a circular dependency between action words 510, 520, 540, 570, and 510. The existence of a loop dependency may cause a system crash or unlimited calls. To address this issue, in some embodiments, computing device 130 may detect whether loops exist in the reference graph of the API associated with the request template of the action word. If no loops exist in the reference graph, the computing device 130 may initiate a call to the API.
In some such embodiments, the computing device 130 may determine the reference map by recursively parsing the references in the request template identified by other action words. For example, the computing device 130 may use a backtracking algorithm to detect loops in the reference graph. In some embodiments, if a loop is detected to exist in the reference graph during the determination of the reference graph, the computing device 130 may cache the detected loop for subsequent detection. For example, computing device 130 may cache loops between action words 540, 550, and 560 after detecting the loops without having to repeat the computation when the relevant action word is encountered again in a subsequent detection.
In some embodiments, to avoid unrestricted calls, e.g., caused by loop dependencies, computing device 130 may set a threshold of times each action word involved during one execution may be executed at most. If the number of times the action word is executed exceeds the threshold while the final result is still not achieved, the computing device 130 may report an error.
As described above with respect to parameter generation of action words, the parameter baseline includes references to other variable parameters, and thus loops may similarly exist in the parameter references. In some such embodiments, the computing device 130 may detect whether a loop exists in the parameter references of the API call associated with performing the test task. For example, in performing a test task, computing device 130 may use a backtracking algorithm to detect whether loops exist in the associated parameter reference graph. If a loop exists, computing device 130 may issue a prompt for the loop's existence and other relevant information, thereby helping the user to revise the task.
Using the methods of the present disclosure, the computing device 130 may implement a more efficient API test workflow. In some embodiments, the workflow may begin with computing device 130 generating a parameter baseline for the parameter and generating an action word definition corresponding to the API. For example, the computing device 130 may provide an interface to the user to write parameter baselines, to receive the user-written parameter baselines and action words, and to store them in a corresponding library. Parameter baselines may be written separately or during the course of writing action words. As previously mentioned, parameters and other action words may be referenced in the definition of an action word.
On this basis, in response to receiving an indication of the test API (e.g., receiving a user selection of an available action word), computing device 130 may generate parameter instance values for the present test according to methods of embodiments of the present disclosure, and automatically parse and orchestrate execution of the plurality of action words involved in the present test. In the automatic arrangement, the parameters of the action word are assigned as the generated parameter instance values. Computing device 130 may then perform an API test corresponding to the action word. As previously described, this may include recursively instantiating and initiating an API request corresponding to the action word concerned, and obtaining and processing a response to the request, and so forth. After execution, computing device 130 may clean up resources created to perform the test (e.g., from the execution stack) and generate a test report.
The computing device 130 may execute the above workflow as a stand-alone device or provide the workflow as a cloud service so that clients may send them their composed action words and execution instructions, etc. It should be understood that the above workflows are by way of example only, and that embodiments of the present disclosure may also be used in other orders and/or combinations. API testing according to embodiments of the present disclosure may significantly reduce the human overhead of test writing, as well as improve the reuse of test case code, and allow for significant improvements in the automation of the orchestration and resource management of API testing.
In some embodiments, computing device 130 may also generate visualizations to perform calls to APIs according to embodiments of the present disclosure. Based on the foregoing automatic orchestration and execution, computing device 130 may generate the graphical API call information at multiple levels of detail. For example, depending on the particular implementation, the computing device 130 may display the visualization on its own graphical user interface, or provide the visualization to the user device for display on the client device.
In some embodiments, at the task level, the computing device 130 may generate a visualization of overall execution information of the one-time execution task. FIG. 6 illustrates an example visualization 600 of task execution that may be generated in accordance with some embodiments of the present disclosure. The visualization 600 may be displayed on a graphical user interface. In this visualization 600, the computing device 130 may generate an axis 610 that indicates the status of execution (e.g., success or failure, time spent) for each execution phase. On axis 610, each execution phase is shown in turn as a node on the axis, as indicated by reference numeral 620.
As further shown by reference numeral 620, the computing device 130 may also generate an indication of the execution status of the subtasks at each stage. Thus, the user can intuitively understand the overall situation of the currently executing task from the axis 610. In addition, computing device 130 may also generate statistics of API calls indicated by the action word execution, as indicated by reference numeral 630. The visualization 600 may provide the user with clear and understandable performance information at the task level.
In some embodiments, computing device 130 may generate a graphical representation of the action word execution process and the related dependencies. FIG. 7 illustrates an example schematic diagram 700 reflecting the order of execution of elements in an action word execution process according to an embodiment of this disclosure. To execute the current action word 730, the computing device 130 first executes various pre-processes 710, such as processes associated with the running environment setup. The computing device 130 then executes the dependent action word 720 that is dependent on the current action word based on the parsing and automatic arrangement of the action word. The computing device 130 may then execute the current action 730 itself.
After execution of the current action word 730 begins, the computing device 130 may initiate a Query Job (Query Job). The query job is used to loop through the state of the API response corresponding to the current action word until the expected value is met or a timeout occurs. When execution of the current action word 730 becomes problematic, the computing device may attempt to re-execute or in some cases may fall back to the pre-process 710. In some embodiments, the query job may be implemented as a special action word "QueryJob" and automatically invoked by computing device 130 when executing other action words. Upon completion of execution of the current action word, whether successful or unsuccessful, computing device 130 may perform post-processing 750, including via resource cleaning, etc., as previously described.
The computing device 130 may, for example, generate a sequence of various processes in the process into a chain representation, and may also include the execution state of each element and related information in the chain representation. In addition, computing device 130 may also include in the representation the execution status and other relevant information of each element, as well as links or buttons or the like for triggering the generation or display of a more detailed visualization (e.g., a call chain of action words).
In some embodiments, for calls to an API encapsulated by a particular action word, computing device 130 may further generate a visual call chain of multiple API calls due to the call and call states of each of the multiple APIs in the visual call chain. In such a call chain, the API may be identified by the corresponding action word name. FIG. 8 illustrates an example visualization 800 of an API call chain that may be generated in accordance with some embodiments of the present disclosure. The visualization 800 may be displayed on a graphical user interface. The visualization 800 includes a graphical representation 810 of a call chain of action words currently being executed, and the execution state of action words involved in the call chain, as indicated by legend 811.
In addition, the computing device 130 may also recursively generate a call chain (e.g., triggered by a user click) that invokes each action word in the chain itself. For example, computing device 130 may further generate a graphical representation 820 of the call chain of action words 812. Such a visualization hierarchy may more intuitively display the execution of action words and the localization of problems that occur in execution than a plain text execution log, making debugging and analyzing API calls easier. For example, the user may intuitively locate the first failed execution in the hierarchy (action word 811 in the example of FIG. 8) to find the root cause of the problem.
It should be understood that the visualizations illustrated and described with respect to fig. 6-8 are by way of example only, and that the computing device 130 may also generate other suitable variants of the visualizations from the automatic parsing, arrangement and execution of action words, such as including other auxiliary information in the visualizations, such as a textual description of the action word, the time of execution, etc.
Fig. 9 illustrates a schematic block diagram of an apparatus 900 for AP testing according to some embodiments of the present disclosure. Apparatus 900 may be implemented as or included in computing device 130 of fig. 1. Apparatus 900 may include a plurality of modules for performing corresponding acts in method 200, such as discussed in fig. 2.
As shown in fig. 9, the apparatus 900 includes an acquisition module 910, a generation module 920, and an initiation module 930. The acquisition module 910 is configured to: in response to receiving an indication to call an API, a predefined template corresponding to the API is obtained based on keywords in the indication that identify the API, the predefined template comprising a request template for the API. The generation module 920 is configured to: an instance value of the variable parameter is generated based on a parameter baseline of the variable parameter in the request template, the parameter baseline describing a generation rule of the value of the variable parameter. The initiation module 930 is configured to: based on the request template and the instance value, a call to the API is initiated.
In some embodiments, the generation module 920 includes: a context acquisition module configured to acquire indicated context information; and an instance value generation module configured to generate an instance value based on the context information and the parameter baseline.
In some embodiments, the initiating module 930 includes: a request generation module configured to generate an instance request for the API based on the request template and the instance value; and a request sending module configured to send the instance request to the API.
In some embodiments, the predefined templates further comprise output templates comprising conversion rules that convert the API's response to the instance request to another structure, and the apparatus 900 further comprises: a response receiving module configured to receive an instance response of the API to the instance request; and a conversion module configured to convert the instance response into an instance output of the execution indication based on the output template.
In some embodiments, the API is a first API, the keyword is a first keyword, and a reference to a second API is also included in the request template, the reference being identified by a second keyword corresponding to the second API.
In some embodiments, apparatus 900 further comprises: a loop detection module configured to detect whether a loop exists in a reference graph of an API associated with the request template; and an initiation determination module configured to determine to initiate a call to the API if no loop exists in the reference map.
In some embodiments, the loop detection module includes: a reference parsing module configured to determine a reference map by recursively parsing references to the APIs in the request template identified by the keywords; and a loop caching module configured to cache the detected loop for subsequent detection if a loop is detected to exist in the reference graph during the determination of the reference graph.
In some embodiments, the parameter baseline includes references to other variable parameters, and the apparatus 900 further includes a parameter loop detection module configured to detect whether a loop exists in the parameter reference graph associated with executing a call to an API.
In some embodiments, the predefined template is a first predefined template, the request template is a first request template, the variable parameter is a first variable parameter, the call is a first call, and the request generation module comprises: a second obtaining module configured to obtain a second predefined template corresponding to a second API based on a second keyword, the second predefined template including a second request template for the second API; a second instance value generation module configured to generate a second instance value of a second variable parameter based on a parameter baseline of the second variable parameter in a second request template; a second initiation module configured to initiate a second call of a second API based on a second request template and a second instance value; and a dependent request generation module configured to generate an instance request based on the request template, the first instance value, and the second call.
In some embodiments, apparatus 900 further comprises: an execution stack creation module configured to create an execution stack based on the request template, the execution stack indicating a calling order of the plurality of APIs that are called as a result of executing the first call; and a resource purging module configured to purge resources created by calling the plurality of APIs during the first call in an order reverse to the calling order.
In some embodiments, the apparatus 900 further comprises a visualization module configured to: a visualization of calls to the execution API is generated, wherein the visualization includes a call chain of a plurality of API calls caused by the call, and call states of each of the plurality of APIs in the call chain.
In some embodiments, the generation module is further configured to: generating a third instance value of the variable parameter based on the parameter baseline in response to receiving a second indication to call the API, the API identified by the keyword in the second indication; and the initiation module is further configured to: a third call of the API is initiated based on the request template and the third instance value.
The acquisition module 910, the generation module 920, and the initiation module 930 may all be implemented by software, or may be implemented by hardware. Illustratively, the implementation of the acquisition module 910 is described next as an example of the acquisition module 910. Similarly, the implementation of the generation module 920 and the initiation module 930 may refer to the implementation of the acquisition module 910.
Module as an example of a software functional unit, the acquisition module 910 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container, among others. Further, the above-described computing examples may be one or more. For example, the and acquisition module 910 may include code running on multiple hosts/virtual machines/containers. It should be noted that, multiple hosts/virtual machines/containers for running the code may be distributed in the same region (region), or may be distributed in different regions. Further, multiple hosts/virtual machines/containers for running the code may be distributed in the same availability zone (availability zone, AZ) or may be distributed in different AZs, each AZ comprising one data center or multiple geographically close data centers. Wherein typically a region may comprise a plurality of AZs.
Also, multiple hosts/virtual machines/containers for running the code may be distributed in the same virtual private cloud (virtual private cloud, VPC) or may be distributed in multiple VPCs. In general, one VPC is disposed in one region, and a communication gateway is disposed in each VPC for implementing inter-connection between VPCs in the same region and between VPCs in different regions.
Module as an example of a hardware functional unit, the acquisition module 910 may include at least one computing device, such as a server or the like. Alternatively, the acquisition module 910 may be a device implemented using an application-specific integrated circuit (ASIC), a programmable logic device (programmable logic device, PLD), or the like. The PLD may be implemented as a complex program logic device (complex programmable logical device, CPLD), a field-programmable gate array (FPGA) GATE ARRAY, a general-purpose array logic (GENERIC ARRAY logic, GAL), or any combination thereof.
The multiple computing devices included in the acquisition module 910 may be distributed in the same region, or may be distributed in different regions, and the multiple computing devices included in the acquisition module 910 may be distributed in the same AZ, or may be distributed in different AZs. Likewise, the multiple computing devices included in the acquisition module 910 may be distributed in the same VPC or may be distributed among multiple VPCs. Wherein the plurality of computing devices may be any combination of computing devices such as servers, ASIC, PLD, CPLD, FPGA, and GAL. It should be noted that, in other embodiments, the acquisition module 910 may be configured to perform any of the processes and actions of the computing device 130 described in connection with fig. 2-8, the generation module 920 may be configured to perform any of the processes and actions of the computing device 130 described in connection with fig. 2-8, and the initiation module 930 may be configured to perform any of the processes and actions of the computing device 130 described in connection with fig. 2-8. The steps that the acquisition module 910, the generation module 920, and the initiation module 930 are responsible for implementing may be specified as needed, with the acquisition module 910, the generation module 920, and the initiation module 930 performing any of the processes and actions of the computing device 130 described in connection with fig. 2-8, respectively, to implement the overall functionality of the apparatus 900.
Embodiments of the present disclosure also provide a computing device 1000. As shown in fig. 10, the computing device 1000 includes: bus 1002, processor 1004, memory 1006, and communication interface 1008. Communication between the processor 1004, memory 1006 and communication interface 1008 is via bus 1002. Computing device 1000 may be a server or a terminal device. It should be understood that the present application is not limited to the number of processors, memories in computing device 1000.
Bus 1002 may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, PCI) bus, or an extended industry standard architecture (extended industry standard architecture, EISA) bus, among others. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, only one line is shown in fig. 10, but not only one bus or one type of bus. Bus 1004 may include a pathway to transfer information between various components of computing device 1000 (e.g., memory 1006, processor 1004, communication interface 1008).
The processor 1004 may include any one or more of a central processing unit (central processing unit, CPU), a graphics processor (graphics processing unit, GPU), a Microprocessor (MP), or a digital signal processor (DIGITAL SIGNAL processor, DSP).
The memory 1006 may include volatile memory (RAM), such as random access memory (random access memory). The processor 1004 may also include non-volatile memory (non-volatile memory), such as read-only memory (ROM), flash memory, mechanical hard disk (HARD DISK DRIVE, HDD) or solid state disk (SSD STATE DRIVE).
The memory 1006 has stored therein executable program code that the processor 1004 executes to implement the functions of the aforementioned acquisition module 910, generation module 920, and initiation module 930, respectively, to implement, for example, the method 200. That is, the memory 106 may have stored thereon instructions for any of the embodiments described above that relate to methods and functions of the computing device 130.
Communication interface 1008 enables communication between computing device 1000 and other devices or communication networks using a transceiver module such as, but not limited to, a network interface card, transceiver, or the like.
Embodiments of the present disclosure also provide a computing device cluster 1100. The cluster of computing devices includes at least one computing device. The computing device may be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device may also be a terminal device such as a desktop, notebook, or smart phone.
As shown in fig. 11, the computing device cluster includes at least one computing device 1000. The memory 1006 in one or more computing devices 1000 in the computing device cluster may have stored therein the same instructions for performing the methods and functions relating to computing device 130 in any of the embodiments described above.
In some possible implementations, portions of instructions for performing the methods and functions of computing device 130 in any of the embodiments described above may also be stored in memory 1006 of one or more computing devices 1000 in the computing device cluster, respectively. In other words, a combination of one or more computing devices 1000 may collectively execute instructions for performing the methods and functions of computing device 130.
It should be noted that, the memories 1006 in different computing devices 1000 in the computing device cluster may store different instructions for performing part of the functions of the apparatus 900. That is, the instructions stored by the memory 1006 in the different computing devices 1000 may implement the functionality of one or more of the acquisition module 910, the generation module 920, and the initiation module 930 (and other additional modules of the apparatus 900 in some embodiments).
In some possible implementations, one or more computing devices in a cluster of computing devices may be connected through a network. Wherein the network may be a wide area network or a local area network, etc. Fig. 12 shows one possible implementation 1200. As shown in fig. 12, two computing devices 1000A and 1000B are connected by a network 1210. Specifically, the connection to the network is made through a communication interface in each computing device. In this type of possible implementation, for example, instructions to perform the functions of the acquisition module 910 are stored in the memory 1006 in the computing device 1000A. Meanwhile, instructions to perform the functions of the generation module 920 and the initiation module 930 are stored in the memory 106 in the computing device 100B.
The manner of connection between clusters of computing devices shown in fig. 12 may be in view of the large amount of user data that the method provided by the present application with respect to computing device 130 requires to store and perform intensive real-time or near real-time calculations, thus allowing for the functionality implemented by generation module 920 and initiation module 930 to be performed by computing device 1000B.
It should be appreciated that the functionality of computing device 1000A shown in fig. 12 may also be performed by multiple computing devices 1000. Likewise, the functionality of computing device 1000B may also be performed by multiple computing devices 1000. Embodiments of the present disclosure also provide a computer program product containing instructions that, when run on a computer, cause the computer to perform the methods and functions of any of the embodiments described above involving the computing device 130.
Embodiments of the present disclosure also provide a computer-readable storage medium having stored thereon computer instructions that, when executed by a processor, cause the processor to perform the methods and functions of any of the embodiments described above with respect to the computing device 130.
In general, the various embodiments of the disclosure may be implemented in hardware or special purpose circuits, software, logic or any combination thereof. Some aspects may be implemented in hardware, while other aspects may be implemented in firmware or software, which may be executed by a controller, microprocessor or other computing device. While various aspects of the embodiments of the disclosure are illustrated and described as block diagrams, flow charts, or using some other pictorial representation, it is well understood that these blocks, apparatus, systems, techniques or methods described herein may be implemented in, as non-limiting examples, hardware, software, firmware, special purpose circuits or logic, general purpose hardware or controller or other computing devices, or some combination thereof.
The present disclosure also provides at least one computer program product tangibly stored on a non-transitory computer-readable storage medium. The computer program product comprises computer executable instructions, such as instructions included in program modules, being executed in a device on a real or virtual processor of a target to perform the processes/methods as described above with reference to the figures. Generally, program modules include routines, programs, libraries, objects, classes, components, data structures, etc. that perform particular tasks or implement particular abstract data types. In various embodiments, the functionality of the program modules may be combined or split between program modules as desired. Machine-executable instructions for program modules may be executed within local or distributed devices. In distributed devices, program modules may be located in both local and remote memory storage media.
Computer program code for carrying out methods of the present disclosure may be written in one or more programming languages. These computer program code may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the computer or other programmable data processing apparatus, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the computer, partly on the computer, as a stand-alone software package, partly on the computer and partly on a remote computer or entirely on the remote computer or server.
In the context of this disclosure, computer program code or related data may be carried by any suitable carrier to enable an apparatus, device, or processor to perform the various processes and operations described above. Examples of carriers include signals, computer readable media, and the like. Examples of signals may include electrical, optical, radio, acoustical or other form of propagated signals, such as carrier waves, infrared signals, etc.
A computer readable medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device or data storage device such as a data center that can contain one or more available media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination thereof. More detailed examples of a computer-readable storage medium include an electrical connection with one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical storage device, a magnetic storage device, or any suitable combination thereof.
Furthermore, although the operations of the methods of the present disclosure are depicted in the drawings in a particular order, this is not required to or suggested that these operations must be performed in this particular order or that all of the illustrated operations must be performed in order to achieve desirable results. Rather, the steps depicted in the flowcharts may change the order of execution. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step to perform, and/or one step decomposed into multiple steps to perform. It should also be noted that features and functions of two or more devices according to the present disclosure may be embodied in one device. Conversely, the features and functions of one device described above may be further divided into multiple devices to be embodied.
The foregoing has described implementations of the present disclosure, and the foregoing description is exemplary, not exhaustive, and not limited to the implementations disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the various implementations described. The terminology used herein was chosen in order to best explain the principles of each implementation, the practical application, or the improvement of technology in the marketplace, or to enable others of ordinary skill in the art to understand each implementation disclosed herein.

Claims (27)

1. An Application Programming Interface (API) testing method, comprising:
In response to receiving an indication of calling an API, acquiring a predefined template corresponding to the API based on keywords in the indication, wherein the predefined template comprises a request template aiming at the API;
Generating an instance value of a variable parameter in the request template based on a parameter baseline of the variable parameter, the parameter baseline describing a generation rule of the value of the variable parameter; and
And initiating the call of the API based on the request template and the instance value.
2. The method of claim 1, wherein generating an instance value of a variable parameter in the request template based on a parameter baseline of the variable parameter comprises:
acquiring the indicated context information; and
The instance value is generated based on the context information and the parameter baseline.
3. The method of claim 1 or 2, wherein initiating the call to the API comprises:
generating an instance request for the API based on the request template and the instance value; and
And sending the instance request to the API.
4. A method according to claim 3, wherein the predefined templates further comprise output templates comprising conversion rules that convert the API's response to an instance request to another structure, and the method further comprises:
receiving an instance response of the API to the instance request; and
The instance response is converted to an instance output that performs the indication based on the output template.
5. The method of claim 3, wherein the API is a first API, the keyword is a first keyword, and further comprising a reference to a second API in the request template, the reference identified by a second keyword corresponding to the second API.
6. The method as recited in claim 5, further comprising:
Detecting whether loops exist in a reference graph of an API (application program interface) associated with the request template; and
If no loop exists in the reference graph, determining to initiate the call of the API.
7. The method of claim 6, wherein detecting whether a loop exists in the reference graph of the API associated with the request template comprises:
determining the reference graph by recursively parsing references to APIs in the request template identified by keywords; and
If a loop is detected to exist in the reference graph during the determination of the reference graph, the detected loop is cached for subsequent detection.
8. The method of claim 1, wherein the parameter baseline includes references to other variable parameters, and further comprising:
a determination is made as to whether a loop exists in the parameter reference graph associated with executing the call to the API.
9. The method of claim 5, wherein the predefined template is a first predefined template, the request template is a first request template, the variable parameter is a first variable parameter, the instance value is a first instance value, the call is a first call, and generating the instance request comprises:
Acquiring a second predefined template corresponding to the second API based on the second keyword, wherein the second predefined template comprises a second request template aiming at the second API;
generating a second instance value of a second variable parameter in the second request template based on a parameter baseline of the second variable parameter;
initiating a second call of the second API based on the second request template and the second instance value; and
The instance request is generated based on the request template, the first instance value, and the second call.
10. The method as recited in claim 9, further comprising:
creating an execution stack based on the request template, the execution stack indicating a calling order of a plurality of APIs that are called as a result of executing the first call; and
And clearing resources created by calling the plurality of APIs during the first call in an order reverse to the calling order.
11. The method as recited in claim 1, further comprising:
A visualization of the calls of the API is generated, wherein the visualization includes a call chain of a plurality of API calls caused by the call and respective call states of the plurality of APIs in the call chain.
12. The method as recited in claim 1, further comprising:
Generating a third instance value of the variable parameter based on the parameter baseline in response to receiving a second indication to invoke the API, the API identified by the keyword in the second indication; and
And initiating a third call of the API based on the request template and the third instance value.
13. An Application Programming Interface (API) testing apparatus, comprising:
An acquisition module configured to acquire a predefined template corresponding to an API based on keywords in the indication, wherein the keywords identify the API, and the predefined template comprises a request template for the API, in response to receiving the indication of calling the API;
A generation module configured to generate an instance value of a variable parameter in the request template based on a parameter baseline of the variable parameter, the parameter baseline describing a generation rule of the value of the variable parameter; and
And an initiating module configured to initiate a call of the API based on the request template and the instance value.
14. The apparatus of claim 13, wherein the generating module comprises:
A context acquisition module configured to acquire context information of the indication; and
An instance value generation module configured to generate the instance value based on the context information and the parameter baseline.
15. The apparatus of claim 13 or 14, wherein the initiating means comprises:
a request generation module configured to generate an instance request for the API based on the request template and the instance value; and
And a request sending module configured to send the instance request to the API.
16. The apparatus of claim 15, wherein the predefined templates further comprise output templates comprising conversion rules that convert responses of the API to instance requests to another structure, and the apparatus further comprises:
a response receiving module configured to receive an instance response of the API to the instance request; and
A conversion module configured to convert the instance response to an instance output that performs the indication based on the output template.
17. The apparatus of claim 15, wherein the API is a first API, the keyword is a first keyword, and further comprising a reference to a second API in the request template, the reference identified by a second keyword corresponding to the second API.
18. The apparatus of claim 17, wherein the apparatus further comprises:
A loop detection module configured to detect whether a loop exists in a reference graph of an API associated with the request template; and
An initiation determination module configured to determine to initiate the call of the API if no loop exists in the reference map.
19. The apparatus of claim 18, wherein the loop detection module comprises:
A reference parsing module configured to determine the reference map by recursively parsing references to APIs in the request template identified by keywords; and
A loop caching module configured to cache a detected loop for subsequent detection if a loop is detected to exist in the reference graph during a determination of the reference graph.
20. The apparatus of claim 13, wherein the parameter baseline includes references to other variable parameters, and further comprising:
a parameter loop detection module configured to detect whether a loop exists in a parameter reference graph associated with executing a call to the API.
21. The apparatus of claim 17, wherein the predefined template is a first predefined template, the request template is a first request template, the variable parameter is a first variable parameter, the instance value is a first instance value, the call is a first call, and the request generation module comprises:
A second obtaining module configured to obtain a second predefined template corresponding to the second API based on the second keyword, the second predefined template including a second request template for the second API;
a second instance value generation module configured to generate a second instance value of a second variable parameter in the second request template based on a parameter baseline of the second variable parameter;
a second initiation module configured to initiate a second call of the second API based on the second request template and the second instance value; and
A dependent request generation module generates the instance request based on the request template, the first instance value, and the second call.
22. The apparatus of claim 21, wherein the apparatus further comprises:
An execution stack creation module configured to create an execution stack indicating a calling order of a plurality of APIs called as a result of executing the first call, based on the request template; and
And a resource clearing module configured to clear resources created by calling the plurality of APIs during the first call in an order reverse to the calling order.
23. The apparatus of claim 13, wherein the apparatus further comprises:
A visualization module configured to generate a visualization of the calls of the API, wherein the visualization includes a call chain of a plurality of API calls caused by the calls and respective call states of the plurality of APIs in the call chain.
24. The apparatus according to claim 13, wherein:
The generating module is further configured to generate a third instance value of the variable parameter based on the parameter baseline in response to receiving a second indication to invoke the API, the API identified by the keyword in the second indication; and
The initiation module is further configured to initiate a third call of the API based on the request template and the third instance value.
25. A cluster of computing devices, comprising at least one computing device, each computing device comprising a processor and a memory;
The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the method of any one of claims 1 to 12.
26. A computer readable storage medium storing computer executable instructions which when executed by a processor implement the method of any one of claims 1 to 12.
27. A computer program product comprising computer executable instructions thereon, which when executed implement the method according to any of claims 1 to 12.
CN202211518033.6A 2022-11-29 2022-11-29 Application programming interface test method, apparatus, device, medium and program product Pending CN118152250A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211518033.6A CN118152250A (en) 2022-11-29 2022-11-29 Application programming interface test method, apparatus, device, medium and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211518033.6A CN118152250A (en) 2022-11-29 2022-11-29 Application programming interface test method, apparatus, device, medium and program product

Publications (1)

Publication Number Publication Date
CN118152250A true CN118152250A (en) 2024-06-07

Family

ID=91295451

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211518033.6A Pending CN118152250A (en) 2022-11-29 2022-11-29 Application programming interface test method, apparatus, device, medium and program product

Country Status (1)

Country Link
CN (1) CN118152250A (en)

Similar Documents

Publication Publication Date Title
CN112765023B (en) Test case generation method and device
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN111125057B (en) Method and device for processing service request and computer system
CN107644075B (en) Method and device for collecting page information
CN108197024B (en) Embedded browser debugging method, debugging terminal and computer readable storage medium
CN110609755A (en) Message processing method, device, equipment and medium for cross-block chain node
CN113050984A (en) Resource calling method and device, electronic equipment and storage medium
CN110688096A (en) Method, device, medium and electronic equipment for constructing application program containing plug-in
CN115982491A (en) Page updating method and device, electronic equipment and computer readable storage medium
CN111782520A (en) Test method and device and electronic equipment
CN114328250A (en) Automatic self-checking method, medium and device for software system
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN111158777A (en) Component calling method and device and computer readable storage medium
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN113656044B (en) Android installation package compression method and device, computer equipment and storage medium
CN113138768B (en) Application package generation method and device, electronic equipment and readable storage medium
EP3872630A2 (en) Request processing method and apparatus, electronic device, and computer storage medium
CN114510334A (en) Class instance calling method and device, electronic equipment and automatic driving vehicle
CN115269431A (en) Interface testing method and device, electronic equipment and storage medium
CN118152250A (en) Application programming interface test method, apparatus, device, medium and program product
CN113220586A (en) Automatic interface pressure test execution method, device and system
CN108459940B (en) Configuration information modification method and device of application performance management system and electronic equipment
CN112416698A (en) Monitoring system expansion method and device, storage medium and electronic equipment
CN113805878B (en) Plug-in engineering method, device, computer system and medium

Legal Events

Date Code Title Description
PB01 Publication