Log output method, device, equipment and storage medium for interface testing
By constructing the initial request method and introducing the log object in the interface automation test, the target request method and object are generated, which solves the problem of repeated printing of log records and improves the log output efficiency of the interface test.
Patent Information
- Application Number
- CN202010742629.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-28
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2040-07-28
AI Technical Summary
In interface automation testing, calling multiple interfaces will cause log records to be printed repeatedly, resulting in low log output efficiency.
By constructing the initial request method and introducing the log object into it, the target request method and objects are generated, the test script is generated based on these objects, and the log object is only called once when executing the script to avoid repeated printing.
Improves the log output efficiency of interface testing, avoids printing out log records multiple times, and enhances testing efficiency.
Smart Images

Figure CN114003484B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing technology, and in particular to a log output method, device, equipment and storage medium for interface testing. Background Art
[0002] At present, when performing interface automation testing, first encapsulate each interface in a class, set the interface request parameters as class attributes in the class, encapsulate the request parameters in the method, then import the Logger class from the logger.py module, call the method in the log to print the request / response information. Import the requests library in the test script, and the request / response log record will be generated when the request is sent.
[0003] However, if more than two interfaces need to be called in one use case, the log records will be printed repeatedly. Therefore, when performing interface automation testing, the log records of the request / response are obtained by the above method, and the log records are printed repeatedly, which makes the log output efficiency of the interface test low. Summary of the invention
[0004] The main purpose of the present invention is to provide a log output method, device, equipment and storage medium for interface testing, aiming to solve the technical problem of low efficiency of log output of interface testing when performing interface automation testing.
[0005] To achieve the above object, an embodiment of the present invention provides a log output method for interface testing, and the log output method for interface testing includes:
[0006] When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method;
[0007] Constructing request parameters of the test request, obtaining a target request object, and generating a test script based on the target request method and the target request object;
[0008] Execute the test script to generate and output the log record corresponding to the test request.
[0009] Preferably, the step of encapsulating the initial request method and introducing a log object into the initial request method to obtain a target request method comprises:
[0010] Detecting whether there is a target method matching the initial request method in a preset request library;
[0011] If there is a target method that matches the initial request method, encapsulate the initial request method according to the target method;
[0012] The log object constructed in the first preset class is introduced into the initial request method to obtain the target request method.
[0013] Preferably, the step of constructing the initial request method corresponding to the test request includes:
[0014] Parsing the test request to obtain information to be tested of the test request;
[0015] According to the method information of the information to be tested, searching the method library for a request method template corresponding to the method information;
[0016] According to the request method template, an initial request method corresponding to the test request is constructed in a second preset class.
[0017] Preferably, the step of constructing the request parameters of the test request and obtaining the target request object includes:
[0018] Obtaining a request object template from a request object library, and constructing an initial request object in the second preset class according to the request object template;
[0019] According to the request object information of the information to be tested, request parameters are constructed for the initial request object to obtain the target request object of the test request.
[0020] Preferably, the step of generating a test script based on the target request method and the target request object includes:
[0021] Importing the target request object into an initial script, and executing the initial script to call the target request method based on the target request object;
[0022] Passing the request parameters in the target request object to the target request method;
[0023] Parameters of the target request method are assigned according to the request parameters to generate a test script.
[0024] Preferably, the step of assigning parameters to the target request method according to the request parameters to generate a test script includes:
[0025] Determine, according to the parameter attribute of the request parameter, a parameter attribute to be assigned corresponding to the parameter attribute in the target request method;
[0026] Insert the parameter value of the request parameter into the parameter value to be assigned corresponding to the parameter attribute to be assigned, assign the parameter value to be assigned, and generate a test script.
[0027] Preferably, the step of executing the test script and generating and outputting a log record corresponding to the test request includes:
[0028] Execute the test script, call the test information corresponding to the test request based on the log object, and generate a log record;
[0029] The log record is output to the position corresponding to each processor in the preset processor group through the preset processor group.
[0030] To achieve the above object, the present invention further provides a log output device for interface testing, the log output device for interface testing comprising:
[0031] The encapsulation module is used for constructing an initial request method corresponding to the test request when receiving the test request, encapsulating the initial request method, and introducing a log object into the initial request method to obtain a target request method;
[0032] A construction module, used to construct request parameters of the test request, obtain a target request object, and generate a test script based on the target request method and the target request object;
[0033] The execution module is used to execute the test script, generate and output the log record corresponding to the test request.
[0034] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a log output device for interface testing, wherein the log output device for interface testing comprises a memory, a processor, and a log output program for interface testing stored in the memory and executable on the processor, wherein the log output program for interface testing implements the steps of the above-mentioned log output method for interface testing when executed by the processor.
[0035] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a storage medium, on which a log output program for interface testing is stored, and when the log output program for interface testing is executed by a processor, the steps of the above-mentioned log output method for interface testing are implemented.
[0036] The embodiment of the present invention provides a log output method, device, equipment and storage medium for interface testing. When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method; request parameters of the test request are constructed to obtain a target request object, and a test script is generated based on the target request method and the target request object; the test script is executed to generate and output the log record corresponding to the test request. The test script for outputting the log record in the present invention is generated by the target request method and the target request object, because the target request method is obtained by introducing the log record while encapsulating the constructed initial request method, and the target request object contains the request parameters of the test request, so that when executing the test script, only one log object needs to be called, avoiding multiple printing and output of the log record, thereby improving the log output efficiency of the interface test. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A schematic diagram of the structure of the hardware operating environment involved in the implementation scheme of the log output method for interface testing of the present invention;
[0038] Figure 2 A flow chart of a first embodiment of a log output method for interface testing of the present invention;
[0039] Figure 3 A flow chart of a second embodiment of a log output method for interface testing of the present invention;
[0040] Figure 4 This is a functional module diagram of a preferred embodiment of a log output device for interface testing of the present invention.
[0041] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0042] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0043] The embodiment of the present invention provides a log output method, device, equipment and storage medium for interface testing. When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method; request parameters of the test request are constructed to obtain a target request object, and a test script is generated based on the target request method and the target request object; the test script is executed to generate and output the log record corresponding to the test request. The test script for outputting the log record in the present invention is generated by the target request method and the target request object, because the target request method is obtained by introducing the log record while encapsulating the constructed initial request method, and the target request object contains the request parameters of the test request, so that when executing the test script, only one log object needs to be called, avoiding multiple printing and output of the log record, thereby improving the log output efficiency of the interface test.
[0044] like Figure 1 As shown, Figure 1 It is a schematic diagram of the structure of a log output device for interface testing of a hardware operating environment involved in an embodiment of the present invention.
[0045] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present invention, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.
[0046] The log output device of the interface test in the embodiment of the present invention may be a PC, or a portable terminal device such as a tablet computer or a portable computer.
[0047] like Figure 1 As shown, the log output device of the interface test may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0048] Those skilled in the art will understand that Figure 1The structure of the log output device for interface testing shown in the figure does not constitute a limitation on the log output device for interface testing, and may include more or less components than those shown in the figure, or a combination of certain components, or a different arrangement of components.
[0049] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a log output program for interface testing.
[0050] exist Figure 1 In the device shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and perform data communication with the client; and the processor 1001 can be used to call the log output program of the interface test stored in the memory 1005, and perform the following operations:
[0051] When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method;
[0052] Constructing request parameters of the test request, obtaining a target request object, and generating a test script based on the target request method and the target request object;
[0053] Execute the test script to generate and output the log record corresponding to the test request.
[0054] Furthermore, the step of encapsulating the initial request method and introducing a log object into the initial request method to obtain a target request method includes:
[0055] Detecting whether there is a target method matching the initial request method in a preset request library;
[0056] If there is a target method that matches the initial request method, encapsulate the initial request method according to the target method;
[0057] The log object constructed in the first preset class is introduced into the initial request method to obtain the target request method.
[0058] Furthermore, the step of constructing the initial request method corresponding to the test request includes:
[0059] Parsing the test request to obtain information to be tested of the test request;
[0060] According to the method information of the information to be tested, searching the method library for a request method template corresponding to the method information;
[0061] According to the request method template, an initial request method corresponding to the test request is constructed in a second preset class.
[0062] Furthermore, the step of constructing the request parameters of the test request and obtaining the target request object includes:
[0063] Obtaining a request object template from a request object library, and constructing an initial request object in the second preset class according to the request object template;
[0064] According to the request object information of the information to be tested, request parameters are constructed for the initial request object to obtain the target request object of the test request.
[0065] Furthermore, the step of generating a test script based on the target request method and the target request object includes:
[0066] Importing the target request object into an initial script, and executing the initial script to call the target request method based on the target request object;
[0067] Passing the request parameters in the target request object to the target request method;
[0068] Parameters of the target request method are assigned according to the request parameters to generate a test script.
[0069] Furthermore, the step of assigning parameters to the target request method according to the request parameters to generate a test script includes:
[0070] Determine, according to the parameter attribute of the request parameter, a parameter attribute to be assigned corresponding to the parameter attribute in the target request method;
[0071] Insert the parameter value of the request parameter into the parameter value to be assigned corresponding to the parameter attribute to be assigned, assign the parameter value to be assigned, and generate a test script.
[0072] Furthermore, the step of executing the test script and generating and outputting a log record corresponding to the test request includes:
[0073] Execute the test script, call the test information corresponding to the test request based on the log object, and generate a log record;
[0074] The log record is output to the position corresponding to each processor in the preset processor group through the preset processor group.
[0075] In order to better understand the above technical solution, exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0076] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0077] Reference Figure 2 , the first embodiment of the present invention provides a flow chart of a log output method for an interface test. In this embodiment, the log output method for the interface test includes the following steps:
[0078] Step S10, when a test request is received, construct an initial request method corresponding to the test request, encapsulate the initial request method, and introduce a log object into the initial request method to obtain a target request method;
[0079] In this embodiment, the log output method of the interface test is applied to the test tool of the interface test. In this embodiment, the test tool is preferably a Python-based tool PyCharm, wherein PyCharm is a Python IDE created by JetBrains. IDE (Integrated Development Environment) is an application program used to provide a program development environment, generally including tools such as a code editor, a compiler, a debugger, and a graphical user interface. JetBrains is a Czech software development company, and Python is a cross-platform computer programming language.
[0080] Furthermore, when the user has an interface test requirement, the information to be tested is set in the test tool PyCharm, and after the information to be tested is completed, a test request is initiated, wherein the information to be tested includes at least method information and request object information, wherein the method information includes the method to be tested for this interface test, and the request object information includes the object to be tested for this interface test. Furthermore, when the test tool receives the test request sent by the user, it constructs a log object in the first preset class, wherein the first preset class is the Logger class in this embodiment, and the log object is used to call log methods of different levels and log content that needs to be output in the test request. Furthermore, the test tool constructs the initial request method of the test request in the second preset class according to the method information in the information to be tested, wherein the second preset class is the Request class in this embodiment. Furthermore, the testing tool searches for the target method from the preset request library according to the initial request method, and when the target method is found, encapsulates the initial request method according to the target method; while encapsulating the initial request method, the system introduces the log object constructed in the first preset class into the initial request method, and after completing the encapsulation and the introduction of the log object, the target request method is obtained, wherein the preset request library stores a variety of request methods. In this embodiment, the preset request library is a third-party library requests, and the requests library is a Python HTTP client library.
[0081] Furthermore, the step of constructing the initial request method corresponding to the test request includes:
[0082] Step S11, parsing the test request to obtain the information to be tested of the test request;
[0083] Step S12, according to the method information of the information to be tested, searching the method library for a request method template corresponding to the method information;
[0084] Step S13: constructing an initial request method corresponding to the test request in a second preset class according to the request method template.
[0085] Further, the test tool parses the received test request. Specifically, the test tool identifies the text content contained in the test request to obtain the information to be tested of the test request, wherein the information to be tested includes at least method information and request object information. In this embodiment, the method information may include one of the request methods such as GET, HEAD and POST. Further, the test tool searches the method library for a request method template corresponding to the request method of the method information based on one of the multiple request methods in the method information, wherein the method library is used to store multiple request method templates for interface testing. Further, if the request method template corresponding to the request method of the method information exists in the method library, the request method template corresponding to the request method is extracted into the second preset class Request class, and the parameter information of the request method in the method information is input into the extracted request method template to construct the initial request method corresponding to the test request.
[0086] Step S20, constructing request parameters of the test request, obtaining a target request object, and generating a test script based on the target request method and the target request object;
[0087] Furthermore, after receiving the test request, the test tool constructs an initial request object through the request object template in the second preset class Request, and constructs request parameters corresponding to the test request in the initial request object according to the request object information in the information to be tested, and obtains the target request object. Furthermore, the test tool calls the target request method through the target request object, passes the request parameters representing the actual parameters in the target request object to the target request method, assigns the parameters representing the formal parameters of the target request method, and after completing the assignment, generates a test script corresponding to the test request, so as to execute the test script, generate and output the log record of the interface test.
[0088] Furthermore, the step of constructing the request parameters of the test request in the initial request object to obtain the target request object includes:
[0089] Step S21, obtaining a request object template from a request object library, and constructing an initial request object in the second preset class according to the request object template;
[0090] Step S22: constructing request parameters for the initial request object according to the request object information of the information to be tested, and obtaining the target request object of the test request.
[0091] Further, the test tool is also provided with a request object library, in which a variety of request object templates required for interface testing are stored, wherein the request object template is used to construct a request object, and the request object in this embodiment is preferably a Request object, and the Request object is used to send a test request. Further, after receiving the test request, the test tool searches the request object library for a request object template corresponding to the test request. Specifically, the test tool can identify the type of the request object to be tested from the information to be tested of the test request, and searches the request object library for a request object template of the same type as the request object to be tested. Further, if a request object template of the same type as the request object to be tested is found, the request object template is extracted, and in the second preset class Request class, the initial request object is constructed by the request object template. Further, the test tool obtains the request object information in the information to be tested, and constructs the request parameters for the initial request object, wherein the request parameters at least include parameter attributes and parameter values. Specifically, the test tool extracts multiple sets of parameters of the request object information in the information to be tested, inserts the multiple sets of parameters into the corresponding positions of the initial request object, constructs the request parameters of the initial request object, and obtains the target request object of the test request.
[0092] Step S30, executing the test script, generating and outputting a log record corresponding to the test request.
[0093] Further, the test tool executes the generated test script, records the test information generated during the test process in a blank log, and generates a test log. Further, the test tool calls the log method and the test log content through the log object to generate a log record, and outputs the generated log record through the preset processor group, and outputs the log record to the position corresponding to each processor of the preset processor group.
[0094] Furthermore, the step of executing the test script and generating and outputting a log record corresponding to the test request includes:
[0095] Step S31, executing the test script, calling the test information corresponding to the test request based on the log object, and generating a log record;
[0096] Step S32: output the log record to the corresponding position of each processor in the preset processor group through the preset processor group.
[0097] Furthermore, the test tool executes the test script generated by the target request object and the target request method, records the test information such as the test location information, test function information, and test result information generated during the test process, and stores the recorded test information in a blank log to generate a test log. Furthermore, the test tool generates log records by calling log methods of different levels and the test log content that needs to be output in the test request through the log object, and transmits the log records to the preset processor group, and outputs the log records through the preset processor group, wherein the preset processor includes at least a stream processor and a file processor. Specifically, the system transmits the log records to the preset processor group, outputs the log records to the console of the test tool through the stream processor included in the preset processor group for display, and outputs the log records to a file for storage through the file processor included in the preset processor group.
[0098] The present embodiment provides a log output method, device, equipment and storage medium for interface testing. When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method; request parameters of the test request are constructed to obtain a target request object, and a test script is generated based on the target request method and the target request object; the test script is executed to generate and output the log record corresponding to the test request. The test script for outputting log records in the present invention is generated by the target request method and the target request object, because the target request method is obtained by introducing the log record while encapsulating the constructed initial request method, and the target request object contains the request parameters of the test request, so that the log object only needs to be called once when executing the test script, avoiding multiple printing and output of log records, thereby improving the log output efficiency of the interface test.
[0099] Further, refer to Figure 3 Based on the first embodiment of the log output method for interface testing of the present invention, a second embodiment of the log output method for interface testing of the present invention is proposed. In the second embodiment, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain the target request method, including:
[0100] Step S14, detecting whether there is a target method matching the initial request method in the preset request library;
[0101] Step S15, if there is a target method matching the initial request method, encapsulate the initial request method according to the target method;
[0102] Step S16, introducing the log object constructed in the first preset class into the initial request method to obtain the target request method.
[0103] Further, the test tool detects from the requests library according to the method name of the initial request method to determine whether there is a request method with the same method name as the initial request method. If there is a request method with the same method name as the initial request method, it is further determined whether the parameters of the request method are the same as the parameters of the initial request method. If the parameters of the request method are the same as the parameters of the initial request method, it will be determined that there is a target method that matches the initial request method. Further, the test tool calls the target method and encapsulates the initial request method according to the parameters in the target method; while encapsulating the initial request method, the test tool introduces the log object constructed in the Logger class into the initial request method by calling in the initial request method. After completing the encapsulation and the introduction of the log object, the target request method is obtained. By generating a test script by encapsulating the initial request method and introducing the log object into the initial request method, when executing the test script, it is only necessary to call the encapsulated target request method through the target request object, call the log object once, and print a log record, avoiding repeated printing of log records caused by calling the log object multiple times, and improving the log output efficiency of the interface test.
[0104] This embodiment encapsulates the initial request method by selecting a target method that matches the initial request method from a preset request library, and introduces a log object into the initial request method to obtain a target request method. When executing a test script generated by the target request method and the target request object, a log record is output by calling the log object once, thereby avoiding repeated printing of log records and improving the log output efficiency of interface testing.
[0105] Further, based on the first embodiment or the second embodiment of the log output method for interface testing of the present invention, a third embodiment of the log output method for interface testing of the present invention is proposed. In the third embodiment, the step of generating a test script based on the target request method and the target request object includes:
[0106] Step S23, importing the target request object into an initial script, and executing the initial script to call the target request method based on the target request object;
[0107] Step S24, passing the request parameters in the target request object to the target request method;
[0108] Step S25, assigning parameters to the target request method according to the request parameters to generate a test script.
[0109] Further, the test tool calls the initial script used to construct the test script, and imports the target request object into the initial script, wherein the initial script contains the general test information required for interface testing. Further, the test tool executes the initial script after importing the target request object, extracts the constructed request parameters from the target request object, and passes the request parameters to the target request method by calling. Further, the test tool determines the parameter attributes to be assigned corresponding to the parameter attributes in the target request method according to the parameter attributes of the request parameters, and inserts the parameter values of the request parameters into the parameter values to be assigned corresponding to the parameter attributes to be assigned, assigns the parameter values to be assigned, and generates a test script.
[0110] Furthermore, the step of assigning parameters to the target request method according to the request parameters to generate a test script includes:
[0111] Step S251, determining, according to the parameter attribute of the request parameter, the parameter attribute to be assigned in the target request method corresponding to the parameter attribute;
[0112] Step S252: insert the parameter value of the request parameter into the parameter value to be assigned corresponding to the parameter attribute to be assigned, assign the parameter value to be assigned, and generate a test script.
[0113] Furthermore, the test tool uses the attribute name of the parameter attribute in the request parameter as a keyword, and searches the target request method for a parameter attribute to be assigned with the same attribute name as the parameter attribute. If there is a parameter attribute to be assigned with the same attribute name as the parameter attribute, an identifier is set at the position of the parameter value to be assigned corresponding to the parameter attribute to be assigned. Furthermore, the test tool inserts the parameter value of the request parameter into the position of the parameter value to be assigned with the identifier, assigns the parameter value to be assigned, and after the assignment is completed, generates a test script for interface testing.
[0114] This embodiment assigns a target request method through the request parameters of the target request object to generate a test script, so that when the test script is executed, the target request method containing the log object is called through the target request object, and the log object is called only once to generate and output a log record corresponding to the test request, thereby avoiding printing and outputting log records multiple times and improving the log output efficiency of the interface test.
[0115] Furthermore, the present invention also provides a log output device for interface testing.
[0116] Reference Figure 4 , Figure 4 This is a functional module diagram of the first embodiment of the log output device for interface testing of the present invention.
[0117] The log output device of the interface test includes:
[0118] The encapsulation module 10 is used for constructing an initial request method corresponding to the test request when receiving the test request, encapsulating the initial request method, and introducing a log object into the initial request method to obtain a target request method;
[0119] A construction module 20, used to construct request parameters of the test request, obtain a target request object, and generate a test script based on the target request method and the target request object;
[0120] The execution module 30 is used to execute the test script, generate and output the log record corresponding to the test request.
[0121] Furthermore, the packaging module 10 includes:
[0122] A parsing unit, used for parsing the test request to obtain the information to be tested of the test request;
[0123] A retrieval unit, configured to retrieve a request method template corresponding to the method information in a method library according to the method information of the information to be tested;
[0124] The first construction unit is used to construct an initial request method corresponding to the test request in a second preset class according to the request method template.
[0125] Furthermore, the packaging module 10 further includes:
[0126] A detection unit, used to detect whether there is a target method matching the initial request method in a preset request library;
[0127] an encapsulation unit, configured to encapsulate the initial request method according to the target method if there is a target method matching the initial request method;
[0128] The introduction unit is used to introduce the log object constructed in the first preset class into the initial request method to obtain the target request method.
[0129] Furthermore, the construction module 20 includes:
[0130] an acquiring unit, configured to acquire a request object template from a request object library, and construct an initial request object in the second preset class according to the request object template;
[0131] The second construction unit is used to construct request parameters for the initial request object according to the request object information of the information to be tested, so as to obtain the target request object of the test request.
[0132] Furthermore, the construction module 20 also includes:
[0133] an importing unit, configured to import the target request object into an initial script, and execute the initial script to call the target request method based on the target request object;
[0134] A transmitting unit, used for transmitting the request parameters in the target request object to the target request method;
[0135] The assignment unit is used to assign parameters to the target request method according to the request parameters to generate a test script.
[0136] Furthermore, the construction module 20 also includes:
[0137] A determination unit, configured to determine, according to the parameter attribute of the request parameter, a parameter attribute to be assigned in the target request method corresponding to the parameter attribute;
[0138] The inserting unit is used to insert the parameter value of the request parameter into the parameter value to be assigned corresponding to the parameter attribute to be assigned, assign the parameter value to be assigned, and generate a test script.
[0139] Furthermore, the execution module 30 includes:
[0140] An execution unit, configured to execute the test script, call the test information corresponding to the test request based on the log object, and generate a log record;
[0141] The output unit is used to output the log record to the corresponding position of each processor in the preset processor group through the preset processor group.
[0142] In addition, the present invention also provides a storage medium, which is preferably a computer-readable storage medium, on which a log output program for interface testing is stored. When the log output program for interface testing is executed by a processor, the steps of each embodiment of the log output method for interface testing are implemented.
[0143] In the embodiments of the log output device and computer-readable medium for interface testing of the present invention, all technical features of the various embodiments of the log output method for interface testing mentioned above are included, and the descriptions and explanations are basically the same as those of the various embodiments of the log output method for interface testing mentioned above, and will not be repeated here.
[0144] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0145] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), and includes several instructions for enabling a terminal device (which can be a fixed terminal, such as an IoT smart device, including smart air conditioners, smart lights, smart power supplies, smart routers and other smart homes; it can also be a mobile terminal, including smart phones, wearable networked AR / VR devices, smart speakers, self-driving cars and many other networked devices) to execute the methods described in the various embodiments of the present invention.
[0147] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A log output method for interface testing, characterized in that: The log output method of the interface test includes: When a test request is received, an initial request method corresponding to the test request is constructed, the initial request method is encapsulated, and a log object is introduced into the initial request method to obtain a target request method; Constructing request parameters of the test request, obtaining a target request object, and generating a test script based on the target request method and the target request object; Execute the test script to generate and output log records corresponding to the test request; The step of encapsulating the initial request method and introducing a log object into the initial request method to obtain a target request method comprises: Detecting whether there is a target method matching the initial request method in a preset request library; If there is a target method that matches the initial request method, encapsulate the initial request method according to the target method; Introducing the log object constructed in the first preset class into the initial request method to obtain the target request method; The step of constructing the initial request method corresponding to the test request includes: Parsing the test request to obtain information to be tested of the test request; According to the method information of the information to be tested, searching the method library for a request method template corresponding to the method information; According to the request method template, construct an initial request method corresponding to the test request in a second preset class; The step of constructing the request parameters of the test request and obtaining the target request object comprises: Obtaining a request object template from a request object library, and constructing an initial request object in the second preset class according to the request object template; According to the request object information of the information to be tested, request parameters are constructed for the initial request object to obtain the target request object of the test request.
2. The log output method for interface testing according to claim 1, characterized in that: The step of generating a test script based on the target request method and the target request object comprises: Importing the target request object into an initial script, and executing the initial script to call the target request method based on the target request object; Passing the request parameters in the target request object to the target request method; Parameters of the target request method are assigned according to the request parameters to generate a test script.
3. The log output method for interface testing as claimed in claim 2, characterized in that: The step of assigning parameters to the target request method according to the request parameters to generate a test script comprises: Determine, according to the parameter attribute of the request parameter, a parameter attribute to be assigned corresponding to the parameter attribute in the target request method; Insert the parameter value of the request parameter into the parameter value to be assigned corresponding to the parameter attribute to be assigned, assign the parameter value to be assigned, and generate a test script.
4. The log output method for interface testing according to claim 1, characterized in that: The step of executing the test script and generating and outputting the log record corresponding to the test request includes: Execute the test script, call the test information corresponding to the test request based on the log object, and generate a log record; The log record is output to the position corresponding to each processor in the preset processor group through the preset processor group.
5. A log output device for interface testing, characterized in that: The log output device of the interface test includes: The encapsulation module is used for constructing an initial request method corresponding to the test request when receiving the test request, encapsulating the initial request method, and introducing a log object into the initial request method to obtain a target request method; The encapsulation module is also used to detect whether there is a target method matching the initial request method in the preset request library; if there is a target method matching the initial request method, encapsulate the initial request method according to the target method; introduce the log object constructed in the first preset class into the initial request method to obtain the target request method; The encapsulation module is also used to parse the test request to obtain the information to be tested of the test request; according to the method information of the information to be tested, retrieve the request method template corresponding to the method information in the method library; according to the request method template, construct the initial request method corresponding to the test request in the second preset class; A construction module, used to construct request parameters of the test request, obtain a target request object, and generate a test script based on the target request method and the target request object; The construction module is also used to obtain a request object template from a request object library, and construct an initial request object in the second preset class according to the request object template; construct request parameters for the initial request object according to the request object information of the information to be tested, and obtain a target request object of the test request; The execution module is used to execute the test script, generate and output the log record corresponding to the test request.
6. A log output device for interface testing, characterized in that: The log output device of the interface test includes a memory, a processor, and a log output program of the interface test stored in the memory and executable on the processor. When the log output program of the interface test is executed by the processor, the steps of the log output method of the interface test as described in any one of claims 1 to 4 are implemented.
7. A storage medium, characterized in that: The storage medium stores a log output program for interface testing, and when the log output program for interface testing is executed by a processor, the steps of the log output method for interface testing as described in any one of claims 1 to 4 are implemented.
