CN115437906A - Test method and device - Google Patents

Test method and device Download PDF

Info

Publication number
CN115437906A
CN115437906A CN202110616349.8A CN202110616349A CN115437906A CN 115437906 A CN115437906 A CN 115437906A CN 202110616349 A CN202110616349 A CN 202110616349A CN 115437906 A CN115437906 A CN 115437906A
Authority
CN
China
Prior art keywords
test
expression
value
dynamic
calculation
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
CN202110616349.8A
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202110616349.8A priority Critical patent/CN115437906A/en
Publication of CN115437906A publication Critical patent/CN115437906A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application provides a test method and a test device. The method comprises the following steps: acquiring a contract file; analyzing the contract file to determine a dynamic calculation expression contained in a field value used for representing the test interface and a field value used for representing the test parameter in the contract file; executing the dynamic calculation expression to determine test parameters and a test interface; and testing the test interface based on the test parameters to obtain a test result so as to realize dynamic test of the test interface.

Description

Test method and device
Technical Field
The present application relates to the field of computer and communications technologies, and in particular, to a test method and apparatus.
Background
With the increasing progress of internet technology, people have higher and higher requirements on application programs. Before an application program is online, an interface in the application program generally needs to be tested to improve the smoothness and the safety of the application program during running.
In the prior art, the interface is usually tested by recording and replaying the request traffic of the interface, but the content in the recorded request traffic may fail over time, such as a timestamp, and the like, thereby possibly causing a test failure.
Disclosure of Invention
The application aims to provide a testing method and a testing device, which can dynamically test a testing interface, so that the possibility of successfully testing the testing interface can be improved to a certain extent.
According to an aspect of an embodiment of the present application, there is provided a test method including: acquiring a contract file; analyzing the contract file to determine a dynamic calculation expression contained in a field value used for representing a test interface and a field value used for representing a test parameter in the contract file; executing the dynamic calculation expression to determine the test parameters and the test interface; and testing the test interface based on the test parameters to obtain a test result.
According to an aspect of an embodiment of the present application, there is provided a test apparatus including: an acquisition module configured to acquire a contract file; the analysis module is configured to analyze the contract file to determine a dynamic calculation expression contained in a field value used for representing a test interface and a field value used for representing a test parameter in the contract file; an execution module configured to execute the dynamic calculation expression to determine the test parameters and the test interface; and the test module is configured to test the test interface based on the test parameters to obtain a test result.
In an embodiment of the application, based on the foregoing scheme, the dynamic computation expression includes a computation function and an expression statement, and the execution module is configured to: searching a dynamic calculation type matched with the calculation function in a type function library of a dynamic calculation type corresponding to a known type function; and calling the calculation function, and executing calculation corresponding to the dynamic calculation type on the expression statement to determine the test parameters and the test interface.
In an embodiment of the application, based on the foregoing solution, if the dynamic computation type matched with the computation function is to compute a result value of a single expression, the execution module is configured to: acquiring the calculation function, and acquiring a single expression statement adjacent to the calculation function in the dynamic calculation expression; calling the calculation function to calculate the result value of the single expression statement to obtain a single result value; and taking the calculation function and a single expression statement adjacent to the calculation function as a single combination to be replaced, and replacing the single combination to be replaced by using the single result value to determine the test parameters and the test interface.
In an embodiment of the application, based on the foregoing solution, if the dynamic computation type matched with the computation function is to compute a result value of a plurality of expressions, the execution module is configured to: acquiring the computation function, and acquiring a plurality of expression statements appearing after the computation function in the dynamic computation expression; calling the calculation function, and calculating the result values of the expression statements according to the sequence of the expression statements to obtain a plurality of result values; and taking the calculation function and a plurality of expression statements appearing after the calculation function as a plurality of combinations to be replaced, and replacing the plurality of combinations to be replaced by using the plurality of result values to determine the test parameters and the test interface.
In an embodiment of the present application, based on the foregoing solution, the execution module is configured to: acquiring a global variable in the dynamic calculation expression, and acquiring a dictionary object used for expressing the value of the global variable; looking up the key-value pair where the dictionary object for representing the value of the global variable is located to determine the value of the global variable; replacing the global variable and the dictionary object for representing the value of the global variable with the value of the global variable to obtain a replaced dynamic calculation expression; and executing the replaced dynamic calculation expression to determine the test parameters and the test interface.
In an embodiment of the present application, based on the foregoing solution, the execution module is configured to: acquiring an external object address, except the test interface, quoted in the dynamic calculation expression; searching a value in the external object address as an external value; replacing the external object address with the external value to obtain a dynamic calculation expression containing the external value; determining the test parameters and the test interface based on the dynamic computational expression including the external value.
In an embodiment of the application, based on the foregoing solution, after replacing the external object address with the external value, the execution module is further configured to: establishing a global variable in the contract file as a storage global variable; and storing the external value and the external object address into the dictionary object for representing the value of the storage global variable in a key-value pair mode.
In one embodiment of the present application, the test parameters include input parameters and expected outputs, and based on the foregoing scheme, the test module is configured to: inputting the input parameters into the test interface to obtain the actual output returned by the test interface; comparing the actual output with the expected output to obtain a comparison result; determining the test result based on the comparison result.
In one embodiment of the present application, the obtaining module is configured to: acquiring test data; determining, based on the test data, the field value for representing a test interface and the field value for representing a test parameter; acquiring a contract template, wherein the contract template comprises a test interface area and a test parameter area; and filling the field value for representing the test interface into the test interface area, and filling the field value for representing the test parameter into the test parameter area to form the contract file.
According to an aspect of embodiments of the present application, there is provided a computer-readable program medium storing computer program instructions which, when executed by a computer, cause the computer to perform the method of any one of the above.
According to an aspect of an embodiment of the present application, there is provided an electronic device including: a processor; a memory having computer readable instructions stored thereon which, when executed by the processor, implement the method of any of the above.
According to an aspect of an embodiment of the present application, there is provided a computer program product or a computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in the various alternative embodiments described above.
The technical scheme provided by the embodiment of the application can have the following beneficial effects:
in the technical scheme provided by some embodiments of the application, the contract file is analyzed by acquiring the contract file, so as to determine the field value used for representing the test interface in the contract file and the dynamic calculation expression contained in the field value used for representing the test parameter; executing the dynamic calculation expression to obtain the results of the dynamic expressions in the test parameters and the test interfaces corresponding to the execution time points so as to determine the test parameters and the test interfaces corresponding to the execution time points; the test interface is tested based on the test parameters to obtain a test result so as to dynamically test the test interface, so that the test failure caused by the time-varying invalidation of the content of the request flow when the request flow using the test interface is recorded and replayed can be avoided, and the possibility of successfully testing the test interface can be improved to a certain extent.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
FIG. 1 shows a schematic diagram of an exemplary system architecture to which aspects of embodiments of the present application may be applied;
FIG. 2A is a diagram illustrating a data sharing system to which aspects of one embodiment of the present application may be applied;
FIG. 2B shows a block chain diagram to which one embodiment of the present application may be applied;
FIG. 2C is a diagram illustrating the generation of new tiles in a blockchain to which one embodiment of the present application may be applied;
FIG. 3 schematically shows a flow diagram of a testing method according to an embodiment of the present application;
FIG. 4 schematically shows a flow diagram of a testing method according to an embodiment of the present application;
FIG. 5 schematically shows a block diagram of a testing device according to an embodiment of the present application;
FIG. 6 is a hardware diagram of an electronic device shown in accordance with an example embodiment.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the embodiments of the present application can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known methods, devices, implementations, or operations have not been shown or described in detail to avoid obscuring aspects of the application.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor means and/or microcontroller means.
The flowcharts shown in the figures are illustrative only and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
Fig. 1 shows a schematic diagram of an exemplary system architecture 100 to which the technical solution of the embodiments of the present application may be applied.
As shown in fig. 1, system architecture 100 may include clients 101, network 102, and server 103. Network 102 serves as a medium for providing communication links between clients 101 and servers 103. Network 102 may include various types of connections, such as wired communication links, wireless communication links, and so forth, which are not limiting in this application.
It should be understood that the number of clients 101, networks 102, and servers 103 in fig. 1 is merely illustrative. There may be any number of clients 101, networks 102, and servers 103, as desired for implementation. For example, the server 103 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a network service, cloud communication, a middleware service, a domain name service, a security service, a CDN, and a big data and artificial intelligence platform. The client 101 may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, and the like.
In an embodiment of the application, the server 103 parses the contract file by acquiring the contract file to determine a dynamic calculation expression contained in a field value used for representing a test interface and a field value used for representing a test parameter in the contract file; executing the dynamic calculation expression to obtain the results of the dynamic expressions in the test parameters and the test interfaces corresponding to the execution time points so as to determine the test parameters and the test interfaces corresponding to the execution time points; the test interface is tested based on the test parameters to obtain a test result so as to dynamically test the test interface, so that the test failure caused by the time-varying invalidation of the content of the request flow when the request flow using the test interface is recorded and replayed can be avoided, and the possibility of successfully testing the test interface can be improved to a certain extent.
It should be noted that the test method provided in the embodiment of the present application is generally executed by the server 103, and accordingly, the test apparatus is generally disposed in the server 103. However, in other embodiments of the present application, the client 101 may also have a similar function as the server 103, so as to execute the test method provided in the embodiments of the present application.
Fig. 2A shows a schematic diagram of an exemplary data sharing system 200 to which technical aspects of embodiments of the present invention may be applied.
Referring to the data sharing system 200 shown in fig. 2A, the data sharing system 200 refers to a system for performing data sharing between nodes. Each node 201 may receive input information and maintain shared data within the data sharing system 200 based on the received input information while operating normally. In order to ensure information intercommunication in the data sharing system 200, an information connection may exist between each node 201 in the data sharing system 200, and information transmission may be performed between the nodes 201 through the information connection. For example, when an arbitrary node 201 in the data sharing system 200 receives input information, other nodes 201 in the data sharing system 200 acquire the input information according to a consensus algorithm, and store the input information as data in shared data, so that the data stored on all nodes 201 in the data sharing system 200 are consistent.
Each node 201 in the data sharing system 200 has a node identifier corresponding thereto, and each node 201 in the data sharing system 200 may store the node identifiers of other nodes 201 in the data sharing system 200, so that the generated block is broadcast to other nodes 201 in the data sharing system 200 according to the node identifiers of other nodes 201. Each node 201 may maintain a node identifier list as shown in the following table, and store the node name and the node identifier in the node identifier list correspondingly. The node identifier may be an IP (Internet Protocol) address and any other information that can be used to identify the node, and table 1 only illustrates the IP address as an example.
Node name Node identification
Node 1 117.114.151.174
Node 2 117.116.189.145
Node N 119.123.789.258
TABLE 1
Fig. 2B shows a schematic diagram of a blockchain to which an embodiment of the present application may be applied.
Each node in the data sharing system 200 stores one and the same blockchain. The block chain is composed of a plurality of blocks, as shown in fig. 2B, the block chain is composed of a plurality of blocks, the starting block includes a block header and a block main body, the block header stores an input information characteristic value, a version number, a timestamp and a difficulty value, and the block main body stores input information; the next block of the starting block takes the starting block as a parent block, the next block also comprises a block head and a block main body, the block head stores the input information characteristic value of the current block, the block head characteristic value of the parent block, the version number, the timestamp and the difficulty value, and the like, so that the block data stored in each block in the block chain is associated with the block data stored in the parent block, and the safety of the input information in the block is ensured.
Fig. 2C shows a schematic diagram of new block generation in a blockchain to which an embodiment of the present application may be applied.
When each block in the block chain is generated, referring to fig. 2C, when the node where the block chain is located receives the input information, the input information is verified, after the verification is completed, the input information is stored in the memory pool, and the hash tree for recording the input information is updated; and then, updating the updating time stamp to the time when the input information is received, trying different random numbers, and calculating the characteristic value for multiple times, so that the calculated characteristic value can meet the following formula:
SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET
wherein SHA256 is a characteristic value algorithm used for calculating a characteristic value; version (version number) is version information of related block protocols in the block chain; prev _ hash is a block head characteristic value of a parent block of the current block; merkle _ root is a characteristic value of the input information; ntime is the update time of the update timestamp; nbits is the current difficulty, is a fixed value within a period of time, and is determined again after exceeding a fixed time period; x is a random number; TARGET is a feature threshold, which can be determined from nbits.
Therefore, when the random number meeting the formula is obtained through calculation, the information can be correspondingly stored, and the block head and the block main body are generated to obtain the current block. Then, the node where the block chain is located sends the newly generated blocks to the other nodes 201 in the data sharing system 200 where the newly generated blocks are located respectively according to the node identifiers of the other nodes 201 in the data sharing system 200, the newly generated blocks are verified by the other nodes 201, and the newly generated blocks are added to the block chain stored by the newly generated blocks after the verification is completed.
In one embodiment of the present application, the input information stored in the data sharing system 200 may be a contract file, test data, test parameters, or an external object other than a test interface, or the like. By using the block chain basic processing method, the efficiency and the accuracy of testing the test interface can be improved.
The implementation details of the technical solution of the embodiment of the present application are set forth in detail below:
fig. 3 schematically shows a flowchart of a testing method according to an embodiment of the present application, where an execution subject of the testing method may be a server, such as the server 103 shown in fig. 1.
Referring to fig. 3, the testing method at least includes steps S310 to S340, which are described in detail as follows:
in step S310, a contract file is acquired.
In an embodiment of the present application, the contract file may be a file written using a Domain-Specific Language (DSL), the contract file may record test parameters required by the test interface and for performing a test on the test interface, and the test parameters may include input parameters and expected output parameters, which are not limited herein.
In one embodiment of the application, the contract file may be a file written in an interpreted language, such as Python, shell language. In other embodiments of the present application, the contract file may be a file written in an interpreted language in conjunction with a data exchange type language, which may be JSON, XML, or the like.
In one embodiment of the present application, test data may be obtained; determining field values for representing test interfaces and field values for representing test parameters based on the test data; acquiring a contract template, wherein the contract template comprises a test interface area and a test parameter area; the method has the advantages that the field value used for representing the test interface is filled in the test interface area, the field value used for representing the test parameter is filled in the test parameter area, and the contract file is formed, so that the contract file is automatically formed, errors caused by manual writing can be avoided compared with a manual writing test code test interface, and the accuracy of a test result can be improved.
In an embodiment of the present application, a field value used for representing a test interface and a field value used for representing a test parameter in the test data may be determined through semantic analysis, and a test interface area and a location of the test parameter area in the contract template may also be determined through semantic analysis.
In an embodiment of the present application, the content used for representing the dynamic test in the test data may be stored in the contract file in a form of a dynamic expression, for example, an expression statement used for representing the dynamic test in the test data may be identified, a computation function corresponding to the dynamic test content may be selected, and a dynamic computation expression composed of the computation function and the expression statement used for representing the dynamic test may be stored in the contract file.
In step S320, the contract file is parsed to determine the dynamic calculation expressions included in the field values for representing the test interfaces and the field values for representing the test parameters in the contract file.
In an embodiment of the application, the process of parsing the contract file may include obtaining field values used for representing the test interface in the contract file and field values used for representing the test parameters in the contract file, then obtaining the dynamic calculation expression from the field values used for representing the test interface, and obtaining the dynamic calculation expression from the field values used for representing the test parameters. The dynamic calculation expression may exist in the field value for representing the test interface and the field value for representing the test parameter, or the dynamic calculation expression may exist only in the field value for representing the test interface or only in the field value for representing the test parameter.
In an embodiment of the application, if the dynamic calculation expression also exists in other field values used for representing other contents in the contract file, when the contract file is analyzed, the dynamic calculation expression in the other field values is also obtained, so that the dynamic calculation expression is executed subsequently to obtain other contents recorded in the contract file, and the test interface can be better tested.
In an embodiment of the present application, the dynamic computing expression may represent a dynamic test that needs to return content, where the returned content may change with time, an execution result obtained by executing the dynamic computing expression may represent the returned content corresponding to the time for executing the dynamic computing expression, for example, if the dynamic computing expression may obtain a current timestamp, the dynamic computing expression value is executed, and thus obtaining the current timestamp may be implemented. However, by recording and playing back the request traffic, the timestamp recorded in the recorded request traffic is the timestamp during recording, and the current timestamp cannot be obtained.
In one embodiment of the present application, a contract file may be parsed using a contract parser.
In step S330, a dynamic calculation expression is executed to determine test parameters and a test interface.
In an embodiment of the present application, the dynamic calculation expression may include a calculation function and an expression statement, and a dynamic calculation type matched with the calculation function may be searched in a type function library of a dynamic calculation type corresponding to a known type function; and calling a calculation function, and executing calculation corresponding to the dynamic calculation type on the expression statement to determine the test parameters and the test interface.
In an embodiment of the present application, the type function and the computation function may be built-in functions in the analytic language, for example, they may be rich standard library functions built in Python, such as eval and exec functions built in Python, which may greatly simplify writing of computation expressions. The type function and the dynamic calculation type that the type function can execute may be stored correspondingly to form a type function library, and the dynamic calculation type corresponding to the type function that is the same as the calculation function in the type function library may be used as the dynamic calculation type that matches the calculation function.
In an embodiment of the present application, a calculation result obtained by performing calculation corresponding to a dynamic calculation type on an expression statement may replace a dynamic expression to obtain a test parameter and a test interface.
In one embodiment of the present application, a dynamic computational expression may be performed using a contract parser.
In an embodiment of the present application, if the dynamic computation type matched with the computation function is a result value of computing a single expression, the computation function may be obtained, and a single expression statement adjacent to the computation function in the dynamic computation expression is obtained; calling a calculation function to calculate a result value of the single expression statement to obtain a single result value; and taking the calculation function and the single expression statement adjacent to the calculation function as a single combination to be replaced, and replacing the single combination to be replaced by using a single result value to determine the test parameters and the test interface.
In one embodiment of the application, a single result value is used for replacing a replacement result obtained by combining a single piece of field values used for representing test parameters to be replaced, and the replacement result is used as the test parameters; the test interface may be replaced with a single result value for indicating a replacement result combined by a single to-be-replaced in the test interface field value.
In an embodiment of the present application, if the dynamic computation type matched with the computation function is to compute a result value of multiple expressions, the computation function may be obtained, and multiple expression statements occurring after the computation function in the dynamic computation expression are obtained; calling a calculation function, and calculating result values of the expression statements according to the sequence of the expression statements to obtain a plurality of result values; and taking the calculation function and a plurality of expression statements appearing after the calculation function as a plurality of combinations to be replaced, and replacing the plurality of combinations to be replaced by a plurality of result values to determine the test parameters and the test interface.
In this embodiment, the plurality of result values may be a plurality of values, the plurality of values respectively correspond to the plurality of expression statements, and the plurality of result values may replace the plurality of expression statements in the order of the plurality of expression statements to which they correspond.
In one embodiment of the application, a plurality of result values can be used for replacing a replacement result obtained by combining a plurality of to-be-replaced groups in a field value representing a test parameter as the test parameter; the test interface may be replaced by a plurality of result values to indicate a replacement result obtained by combining a plurality of to-be-replaced values in the test interface field value.
In an embodiment of the present application, the multiple expression statements may form a calculation process, for example, the comparison process between the returned result and the expected result may be more complicated, and a value of the boolean type is finally obtained.
In one embodiment of the present application, a contract document is provided, comprising:
Figure BDA0003097839550000101
Figure BDA0003097839550000111
in this embodiment, when the contract parser executes the contract file, a prefix of the field value may be identified to identify the dynamic calculation type of the dynamic calculation expression. For example, if the dynamic calculation type corresponding to the calculation function eval is the result value of calculating a single expression, then "# eval # int (datatime. Now ()"), timestamp () "in the contract file indicates that the execution int (datatime. Now ()), timestamp (), of the eval function is called.
In this embodiment, if the dynamic computation type corresponding to the computation function exec is a result value of computing a plurality of expressions, then "# exec # import string in the contract file; all _ chars = string.ascii _ upper case + string.digits; exec _ result = ″ "represents that an exec function is called to execute import string; all _ chars = string.ascii _ upstream + string.digits, and a plurality of calculated result values are uniformly assigned to a specific environment variable, namely in the exec _ result variable, after the contract parser executes exec call, the environment variable is read to obtain a calculation result.
In this embodiment, if the field value for representing the test interface and the field value for representing the test parameter in the contract file include a non-string type or the calculation function does not match the type function library, the representation is a normal static field value and dynamic calculation is not required.
In this embodiment, after the analysis calculation, a dynamically calculated contract file can be obtained, and the contents can be as follows:
Figure BDA0003097839550000112
Figure BDA0003097839550000121
in one embodiment of the present application, a global variable in a dynamic calculation expression may be obtained, and a dictionary object for representing a value of the global variable is obtained; looking up a key-value pair where a dictionary object for representing a value of a global variable is located to determine the value of the global variable; replacing the global variable and a dictionary object (dit object) for representing the value of the global variable with the value of the global variable to obtain a replaced dynamic calculation expression; and executing the replaced dynamic calculation expression to determine the test parameters and the test interface so as to reference the values stored in the key value pair, wherein the values stored in the key value pair can be calculated before the dynamic calculation expression is executed.
In this embodiment, execution results from executing other expressions, which are obtained before executing the dynamic calculation expression in the contract file, may be stored in a key-value pair (key-value) to enable referencing the calculated value.
In an embodiment of the present application, if the dynamic calculation expression includes a global variable, it may be determined that a dynamic calculation type corresponding to the dynamic calculation expression refers to a calculated value, for the type, the global variable in the dynamic calculation expression may be obtained, a value of the global variable may be searched, the global variable and a dictionary object used for representing the value of the global variable are replaced with the value of the global variable, a replaced dynamic calculation expression is obtained, and the replaced dynamic calculation expression is executed to determine the test parameter and the test interface.
In an embodiment of the present application, executing the replaced dynamic calculation expression may be to obtain a calculation function and an expression statement in the replaced dynamic calculation expression, determine a dynamic calculation type corresponding to the replaced dynamic calculation expression based on the calculation function, and call the calculation function to execute calculation of the dynamic calculation type corresponding to the replaced dynamic calculation expression on the expression statement to determine the test parameter and the test interface, where the specific execution step may refer to the above embodiment.
In an embodiment of the present application, a parsing context may be simulated in the contract parser, and the contract file that has been dynamically calculated in the above embodiment is stored in the context in a key-value manner, that is, may be referred to. For example, a dictionary type (dit type) in Python can be used to represent such a context, and the segmented _ context initialization is a global variable whose value is an empty dit object. Following the above example, after parsing calculation, the content of the paired _ context will become:
Figure BDA0003097839550000122
Figure BDA0003097839550000131
in one embodiment of the application, an external object address, other than a test interface, referenced in a dynamic computational expression may be obtained; searching a value in the external object address as an external value; replacing the external object address with an external value to obtain a dynamic calculation expression containing the external value; and determining test parameters and a test interface based on the dynamic calculation expression containing the external value.
In an embodiment of the present application, a computation function and an expression statement in a dynamic computation expression including an external value may be obtained, a dynamic computation type corresponding to the dynamic computation expression including the external value is determined based on the computation function, and the computation function is called to execute the dynamic computation type corresponding to the dynamic computation expression including the external value on the expression statement to determine a test parameter and a test interface, where the specific execution step may refer to the above embodiment.
In one embodiment of the present application, continuing with the above example, assuming that in the expected output at this time, a field value consistent with the requested data is required to be returned, as can be shown by the following direct reference:
Figure BDA0003097839550000132
Figure BDA0003097839550000133
this quote operation is actually a single valued expression, and can be evaluated using the eval function described above for evaluating a single expression.
In an embodiment of the application, if the dynamic calculation expression includes an external object address, it may be determined that a dynamic calculation type corresponding to the dynamic calculation expression is a result of referring to the external service, and for the type of the dynamic calculation type that is the result of referring to the external service, the external object address in the dynamic calculation expression may be obtained, and a value in the external object address may be searched for as an external value; replacing the external object address with an external value to obtain a dynamic calculation expression containing the external value; and determining test parameters and a test interface based on a dynamic calculation expression containing an external value. For example, when it is expected that the interface to be tested will generate a certain side effect, and it is necessary to check whether the interface meets the expectation by querying the database, the database address may be used as the external object address, and the database may be queried by dynamically calculating the expression. The introduction mode of the database can be defined through a data exchange language, and an absolute path of database codes can be added into the dynamic calculation expression to query the database.
In an embodiment of the present application, the external Object may be an external interface, and an Object may be represented by a data exchange language, for example, an Object type (Object type) in JSON, where the Object may include a request address and a request parameter for calling the external interface, and the contract parser may parse and execute the Object to obtain a calling result of the external interface, and the content of the contract file may be as follows:
Figure BDA0003097839550000141
in this embodiment, the method may be adapted according to a specific external object calling manner, for example, an external target service and an interface ID are required in a remote calling scenario, and a complete URL is required in an http api calling scenario. After the resolver initiates a call accordingly, the response result is saved in the paired _ context in a key-value manner for other logic calculation.
In an embodiment of the present application, after replacing an external object address with an external value, a global variable may be established in a contract file as a storage global variable, and a dictionary object for representing a value of the storage global variable at initialization may be set to null; and storing the external value and the external object address into a dictionary object for representing the value of the global variable in a key-value pair mode, so that other data in the contract file can refer to the external value by looking up the key-value pair according to the external object address.
With continued reference to fig. 3, in step S340, the test interface is tested based on the test parameters to obtain a test result.
In one embodiment of the application, the test parameters include input parameters and expected output, and the input parameters can be input into the test interface to obtain actual output returned by the test interface; comparing the actual output with the expected output to obtain a comparison result; based on the comparison result, a test result is determined.
In one embodiment of the present application, it may be that the actual output is the same as the expected output or the error does not exceed a set error value, then the test interface is determined to pass the test, otherwise, the test interface is determined not to pass the test.
In the embodiment of fig. 3, by acquiring the contract file, parsing the contract file to determine the field value used for representing the test interface and the dynamic calculation expression contained in the field value used for representing the test parameter in the contract file; executing the dynamic calculation expression to obtain the results of the dynamic expressions in the test parameters and the test interfaces corresponding to the execution time points so as to determine the test parameters and the test interfaces corresponding to the execution time points; the test interface is tested based on the test parameters to obtain a test result so as to dynamically test the test interface, so that the test failure caused by the failure of the content of the request flow along with the change of time when the request flow using the test interface is recorded and replayed can be avoided, and the possibility of successfully testing the test interface can be improved to a certain extent.
In this embodiment, a contract test is performed on a test interface by using a contract file, that is, the interface test is performed based on the definition of a call constraint and an expected behavior preset by the interface, and a dynamic test is performed by executing a dynamic expression, so that the contract test has a dynamic request capability. The embodiment can adapt to the scene of dynamic change of the request content, avoids unnecessary repeated maintenance of the static contract content, replaces manual writing of test codes by using a uniform contract resolver, only needs to concentrate on describing a contract protocol, and greatly reduces the cost for realizing the contract test.
In an embodiment of the application, a management page package can be added on the upper layer of the technology, and an operator does not need to directly edit the contract description, but performs visual operation on a management end, and stores the database instead of the contract file.
Fig. 4 schematically shows a flowchart of a testing method according to an embodiment of the present application, where an execution subject of the testing method may be a server, such as the server 103 shown in fig. 1.
Referring to fig. 4, the testing method at least includes steps S410 to S480, which are described in detail as follows:
in step S410, the tester writes a contract file;
in step S420, the tester initiates a test to the contract resolver;
in step S430, the contract parser reads the contract file;
in step S440, the contract parser parses the contract file;
in step S450, the contract parser generates request parameters according to the contract file;
in step S460, the contract resolver initiates a call to the interface to be tested;
in step S470, the tested interface returns a result;
in step S480, the contract parser compares the expected results and outputs a test conclusion.
In the embodiment of fig. 4, the interface to be tested is the above test interface, and the contract file is automatically analyzed by using the contract analyzer to automatically test the interface to be tested, so that a test conclusion can be accurately and conveniently obtained.
Embodiments of the apparatus of the present application are described below, which may be used to perform the testing methods of the above-described embodiments of the present application. For details which are not disclosed in the embodiments of the apparatus of the present application, reference is made to the embodiments of the test method described above in the present application.
FIG. 5 schematically shows a block diagram of a testing device according to an embodiment of the present application.
Referring to fig. 5, a testing apparatus 500 according to an embodiment of the present application includes an obtaining module 501, an analyzing module 502, an executing module 503, and a testing module 504.
According to an aspect of the embodiment of the present application, based on the foregoing scheme, the obtaining module 501 is configured to obtain a contract file; the parsing module 502 is configured to parse the contract file to determine a dynamic calculation expression contained in a field value used for representing the test interface and a field value used for representing the test parameter in the contract file; the execution module 503 is configured to execute the dynamic calculation expression to determine the test parameters and the test interface; the test module 504 is configured to test the test interface based on the test parameters to obtain a test result.
In an embodiment of the present application, based on the foregoing solution, the dynamic computation expression includes a computation function and an expression statement, and the execution module 503 is configured to: searching a dynamic calculation type matched with the calculation function in a type function library of the dynamic calculation type corresponding to the known type function; and calling a calculation function, and executing calculation corresponding to the dynamic calculation type on the expression statement to determine the test parameters and the test interface.
In an embodiment of the present application, based on the foregoing solution, if the dynamic computation type matched with the computation function is to compute a result value of a single expression, the execution module 503 is configured to: acquiring a calculation function, and acquiring a single expression statement adjacent to the calculation function in a dynamic calculation expression; calling a calculation function to calculate the result value of the single expression statement to obtain a single result value; and taking the calculation function and the single expression statement adjacent to the calculation function as a single combination to be replaced, and replacing the single combination to be replaced by using a single result value to determine the test parameters and the test interface.
In an embodiment of the application, based on the foregoing solution, if the dynamic computation type matched with the computation function is to compute the result values of multiple expressions, the execution module 503 is configured to: acquiring a calculation function, and acquiring a plurality of expression statements appearing after the calculation function in the dynamic calculation expression; calling a calculation function, and calculating result values of the expression statements according to the sequence of the expression statements to obtain a plurality of result values; and taking the calculation function and a plurality of expression statements appearing after the calculation function as a plurality of combinations to be replaced, and replacing the plurality of combinations to be replaced by a plurality of result values to determine the test parameters and the test interface.
In an embodiment of the present application, based on the foregoing solution, the execution module 503 is configured to: acquiring a global variable in the dynamic calculation expression, and acquiring a dictionary object for expressing the value of the global variable; looking up a key-value pair where a dictionary object for representing a value of a global variable is located to determine a value of the global variable; replacing the global variable and the dictionary object used for expressing the value of the global variable with the value of the global variable to obtain a replaced dynamic calculation expression; and executing the replaced dynamic calculation expression to determine the test parameters and the test interface.
In an embodiment of the present application, based on the foregoing solution, the execution module 503 is configured to: acquiring external object addresses, except for a test interface, quoted in the dynamic calculation expression; searching a value in the external object address as an external value; replacing the external object address with an external value to obtain a dynamic calculation expression containing the external value; and determining test parameters and a test interface based on the dynamic calculation expression containing the external value.
In an embodiment of the application, based on the foregoing solution, after replacing the external object address with the external value, the execution module 503 is further configured to: establishing a global variable in the contract file as a storage global variable; and storing the external value and the external object address into a dictionary object for representing the value of the global variable in a key-value pair mode.
In one embodiment of the present application, the test parameters include input parameters and expected outputs, and based on the above solution, the test module 504 is configured to: inputting input parameters into the test interface to obtain actual output returned by the test interface; comparing the actual output with the expected output to obtain a comparison result; based on the comparison result, a test result is determined.
In one embodiment of the present application, the obtaining module 501 is configured to: acquiring test data; determining field values for representing test interfaces and field values for representing test parameters based on the test data; acquiring a contract template, wherein the contract template comprises a test interface area and a test parameter area; and filling a field value for representing the test interface into the test interface area, and filling a field value for representing the test parameter into the test parameter area to form the contract file.
As will be appreciated by one skilled in the art, aspects of the present application may be embodied as a system, method or program product. Accordingly, various aspects of the present application may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 60 according to this embodiment of the present application is described below with reference to fig. 6. The electronic device 60 shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 6, the electronic device 60 is in the form of a general purpose computing device. The components of the electronic device 60 may include, but are not limited to: the at least one processing unit 61, the at least one memory unit 62, a bus 63 connecting different system components (including the memory unit 62 and the processing unit 61), and a display unit 64.
Wherein the storage unit stores program code executable by the processing unit 61 to cause the processing unit 61 to perform the steps according to various exemplary embodiments of the present application described in the section "example methods" above in this specification.
The storage unit 62 may include readable media in the form of volatile memory units, such as a random access memory unit (RAM) 621 and/or a cache memory unit 622, and may further include a read only memory unit (ROM) 623.
The storage unit 62 may also include a program/utility 624 having a set (at least one) of program modules 625, such program modules 625 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 63 may be any of several types of bus structures including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 60 may also communicate with one or more external devices (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 60, and/or with any device (e.g., router, modem, etc.) that enables the electronic device 60 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 65. Also, the electronic device 60 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 66. As shown, network adapter 66 communicates with the other modules of electronic device 60 via bus 63. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with electronic device 60, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present application.
There is also provided, in accordance with an embodiment of the present application, a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, various aspects of the present application may also be implemented in the form of a program product comprising program code for causing a terminal device to perform the steps according to various exemplary embodiments of the present application described in the "exemplary methods" section above of this specification, when the program product is run on the terminal device.
According to one embodiment of the present application, a program product for implementing the above method may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto, and in this document, a readable storage 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.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, 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 fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In situations involving remote computing devices, the remote computing devices may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to external computing devices (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes involved in methods according to exemplary embodiments of the present application, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (10)

1. A method of testing, comprising:
acquiring a contract file;
analyzing the contract file to determine a dynamic calculation expression contained in a field value used for representing a test interface and a field value used for representing a test parameter in the contract file;
executing the dynamic calculation expression to determine the test parameters and the test interface;
and testing the test interface based on the test parameters to obtain a test result.
2. The method of claim 1, wherein the dynamic computing expression includes a computing function and an expression statement, and wherein executing the dynamic computing expression to determine the test parameters and the test interface comprises:
searching a dynamic calculation type matched with the calculation function in a type function library of the dynamic calculation type corresponding to the known type function;
and calling the calculation function, and executing calculation corresponding to the dynamic calculation type on the expression statement to determine the test parameters and the test interface.
3. The method according to claim 2, wherein if the dynamic computation type matching the computation function is a result value of computing a single expression, the invoking the computation function and performing computation corresponding to the type of the dynamic computation expression on the expression statement to determine the test parameters and the test interface comprises:
acquiring the calculation function, and acquiring a single expression statement adjacent to the calculation function in the dynamic calculation expression;
calling the calculation function to calculate the result value of the single expression statement to obtain a single result value;
and taking the calculation function and a single expression statement adjacent to the calculation function as a single combination to be replaced, and replacing the single combination to be replaced by using the single result value to determine the test parameters and the test interface.
4. The method of claim 2, wherein if the dynamic computation type matching the computation function is a result value of computing a plurality of expressions, the invoking the computation function and performing computation corresponding to the type of the dynamic computation expression on the expression statement to determine the test parameters and the test interface comprises:
acquiring the computation function, and acquiring a plurality of expression statements appearing after the computation function in the dynamic computation expression;
calling the calculation function, and calculating the result values of the expression statements according to the sequence of the expression statements to obtain a plurality of result values;
taking the calculation function and a plurality of expression statements appearing after the calculation function as a plurality of combinations to be replaced,
and replacing the plurality of combinations to be replaced by the plurality of result values to determine the test parameters and the test interface.
5. The method of claim 1, wherein said executing the dynamic computational expression to determine the test parameters and the test interface comprises:
acquiring a global variable in the dynamic calculation expression, and acquiring a dictionary object used for expressing the value of the global variable;
looking up the key-value pair where the dictionary object for representing the value of the global variable is located to determine the value of the global variable;
replacing the global variable and the dictionary object for representing the value of the global variable with the value of the global variable to obtain a replaced dynamic calculation expression;
and executing the replaced dynamic calculation expression to determine the test parameters and the test interface.
6. The method of claim 1, wherein said executing a dynamic computational expression included in said field value to determine said test parameters and said test interface comprises:
acquiring an external object address, except the test interface, quoted in the dynamic calculation expression;
searching a value in the external object address as an external value;
replacing the external object address with the external value to obtain a dynamic calculation expression containing the external value;
determining the test parameters and the test interface based on the dynamic computational expression including the external value.
7. The method of claim 6, wherein after replacing the external object address with the external value, the method further comprises:
establishing a global variable in the contract file as a storage global variable;
and storing the external value and the external object address into the dictionary object for representing the value of the storage global variable in a key-value pair mode.
8. The method of claim 1, wherein the test parameters include input parameters and expected outputs, and the testing the test interface based on the test parameters to obtain a test result comprises:
inputting the input parameters into the test interface to obtain the actual output returned by the test interface;
comparing the actual output with the expected output to obtain a comparison result;
determining the test result based on the comparison result.
9. The testing method of claim 1, wherein the obtaining the contract file comprises:
acquiring test data;
determining, based on the test data, the field value for representing a test interface and the field value for representing a test parameter;
acquiring a contract template, wherein the contract template comprises a test interface area and a test parameter area;
and filling the field value for representing the test interface into the test interface area, and filling the field value for representing the test parameter into the test parameter area to form the contract file.
10. A test apparatus, comprising:
an acquisition module configured to acquire a contract file;
the analysis module is configured to analyze the contract file to determine a dynamic calculation expression contained in a field value used for representing a test interface and a field value used for representing a test parameter in the contract file;
an execution module configured to execute the dynamic calculation expression to determine the test parameters and the test interface;
and the test module is configured to test the test interface based on the test parameters to obtain a test result.
CN202110616349.8A 2021-06-02 2021-06-02 Test method and device Pending CN115437906A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110616349.8A CN115437906A (en) 2021-06-02 2021-06-02 Test method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110616349.8A CN115437906A (en) 2021-06-02 2021-06-02 Test method and device

Publications (1)

Publication Number Publication Date
CN115437906A true CN115437906A (en) 2022-12-06

Family

ID=84240079

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110616349.8A Pending CN115437906A (en) 2021-06-02 2021-06-02 Test method and device

Country Status (1)

Country Link
CN (1) CN115437906A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370217A (en) * 2023-12-08 2024-01-09 天津华来科技股份有限公司 Automatic interface test result generation method based on python

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370217A (en) * 2023-12-08 2024-01-09 天津华来科技股份有限公司 Automatic interface test result generation method based on python

Similar Documents

Publication Publication Date Title
US9582399B2 (en) Entropy weighted message matching for opaque service virtualization
US10031836B2 (en) Systems and methods for automatically generating message prototypes for accurate and efficient opaque service emulation
US10467316B2 (en) Systems and methods for web analytics testing and web development
US20160277510A1 (en) Response prototypes with robust substitution rules for service virtualization
CN113076104A (en) Page generation method, device, equipment and storage medium
CN113076729B (en) Method and system for importing report, readable storage medium and electronic equipment
CN112306881A (en) Simulation data generation method, device, equipment and storage medium
CN112154420A (en) Automatic intelligent cloud service testing tool
WO2020140624A1 (en) Method for extracting data from log, and related device
US9166619B2 (en) Method and system for pattern-based compression
CN110719200A (en) Information identification method and device
CN115437906A (en) Test method and device
CN111124883B (en) Test case library introduction method, system and equipment based on tree form
US11182272B2 (en) Application state monitoring
CN115454702A (en) Log fault analysis method and device, storage medium and electronic equipment
CN114519071A (en) Generation method, matching method, system, device and medium of rule matching model
CN113268483A (en) Request processing method and device, electronic equipment and storage medium
CN111563389B (en) Translation method and device for original content of user
Du Opaque response generation enabling automatic creation of virtual services for service virtualisation
CN115168673B (en) Data graphical processing method, device, equipment and storage medium
US11675838B2 (en) Automatically completing a pipeline graph in an internet of things network
CN113448822B (en) Test method, test device, computer readable medium and electronic equipment
US20230252360A1 (en) Efficient optimization of machine learning models
CN109977221B (en) User verification method and device based on big data, storage medium and electronic equipment
CN115757145A (en) Method, device, equipment and storage medium for developing client interface

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination