CN110781082B - Method, device, medium and equipment for generating test case of interface - Google Patents

Method, device, medium and equipment for generating test case of interface Download PDF

Info

Publication number
CN110781082B
CN110781082B CN201910974309.3A CN201910974309A CN110781082B CN 110781082 B CN110781082 B CN 110781082B CN 201910974309 A CN201910974309 A CN 201910974309A CN 110781082 B CN110781082 B CN 110781082B
Authority
CN
China
Prior art keywords
file
interface
test case
class
target
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.)
Active
Application number
CN201910974309.3A
Other languages
Chinese (zh)
Other versions
CN110781082A (en
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 CN201910974309.3A priority Critical patent/CN110781082B/en
Publication of CN110781082A publication Critical patent/CN110781082A/en
Application granted granted Critical
Publication of CN110781082B publication Critical patent/CN110781082B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/3684Test management for test design, e.g. generating new test cases

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 disclosure relates to the technical field of computers, and provides a method and a device for generating a test case of an interface, a computer storage medium and electronic equipment. Wherein, the method comprises the following steps: converting a first file in a Proto format for interface description into a second file in a target format; analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information; determining a target parameter according to the class description information and the nesting relation information; and generating a test case of the interface according to the target parameters. This technical scheme is enough effectively to promote interface efficiency of software testing.

Description

Method, device, medium and equipment for generating test case of interface
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for generating a test case of an interface, and a computer storage medium and an electronic device for implementing the method for generating a test case of an interface.
Background
The Protocol Buffer is a data storage format of structured data, and serializes (serializes) the structured data to realize a function of data storage/Remote Procedure Call (RPC) data exchange. Under the demand scene with larger data transmission quantity, the Protocol Buffer occupies smaller space than the serialized tools of XML, JSON and other structural data and has higher processing speed, and meanwhile, the Protocol Buffer can be used in a cross-platform and cross-voice mode. The method can be particularly applied to the fields of network transmission, configuration files, data storage and the like. Among them, the background interface defined by Proto has been widely applied to many development projects.
The method for generating the test case of the interface provided by the related technology comprises the following steps: the interface name and the related interface parameters are obtained through an interface (Application, abbreviated as API) description file (such as an interface description file in JSON format provided by development), or through test-collated information. And further, filling the obtained interface name and the related interface parameters into a test case template to obtain a test case. Therefore, the test of the corresponding interface is carried out through the test case.
However, the related art needs manual arrangement or development of supporting descriptive documents when acquiring the interface parameters. Wherein manual organization can result in increased time consumption, and the development-supported descriptive documents depend on whether the framework used by the development supports the corresponding project. That is, the interface test efficiency of the related art providing scheme is to be improved.
It is to be noted that the information disclosed in the background section above is only used to enhance understanding of the background of the present disclosure.
Disclosure of Invention
The present disclosure is directed to a method and an apparatus for generating a test case of an interface, and a computer storage medium and an electronic device for implementing the method for generating a test case of an interface, so as to improve interface test efficiency to at least a certain extent.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to an aspect of the present disclosure, a method for generating a test case of an interface is provided, including:
converting a first file in a Proto format for interface description into a second file in a target format; analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information; determining target parameters according to the class description information and the nesting relation information; and generating a test case of the interface according to the target parameters.
According to an aspect of the present disclosure, an apparatus for generating a test case of an interface is provided, including: the device comprises a conversion module, an analysis module, a parameter determination module and a test case generation module. Wherein:
the above-mentioned conversion module is configured to: converting a first file in a Proto format for interface description into a second file in a target format; the parsing module is configured to: analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information; the parameter determination module is configured to: determining target parameters according to the class description information and the nesting relation information; the test case generation module is configured to: and generating a test case of the interface according to the target parameters.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parsing module is specifically configured to:
determining a first type description of the target format according to the message structure body of the first file; determining a second type description and an associated file type description of the target format according to the enumeration structure of the first file; and analyzing the field keywords described by the first type to determine the nesting relation information of the message structure, and analyzing the field keywords described by the associated file type to determine the nesting relation information of the associated file in the enumeration structure.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parameter determining module is specifically configured to:
judging whether the current processing class is a nested structure according to the nesting relation information; if the current processing class is not a nested structure, then:
extracting a data type dictionary and a modified label dictionary related to the current processing class through a regular expression; and determining the target parameters of the current processing class according to the values of the data type dictionary and the values of the modified label dictionary.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parameter determining module is specifically further configured to:
if the current processing class is a nested structure, then:
determining the next processing class according to the nesting relation information; extracting a data type dictionary and a modified label dictionary about the next processing class through a regular expression; and determining the target parameter of the next processing class according to the value of the data type dictionary and the value of the modified label dictionary.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parsing module is further specifically configured to:
acquiring the name of an interface, and filtering a target class according to the interface name; and analyzing the mapping relation between the first file and the second file to obtain the class description information and the nesting relation information of the target class.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module is specifically configured to:
and acquiring a test case template, and filling the interface name and the target parameters of the target class into the test case template to obtain the test case of the interface.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module is further specifically configured to:
and generating a test case of the interface according to the target parameters, and storing the test case into a block chain.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module is further specifically configured to:
and taking the interface name and the target parameter as JSON objects, and rendering the JSON objects to the test case template.
According to an aspect of the present disclosure, there is provided a computer storage medium having a computer program stored thereon, the computer program, when executed by a processor, implementing the method for generating test cases for an interface according to the first aspect.
According to an aspect of the present disclosure, there is provided an electronic device including: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the method for generating the test case of the interface according to the first aspect by executing the executable instructions.
As can be seen from the foregoing technical solutions, the method and the apparatus for generating a test case of an interface, and the computer storage medium and the electronic device for implementing the method for generating a test case of an interface in the exemplary embodiments of the present disclosure have at least the following advantages and positive effects:
in the technical solution provided in some embodiments of the present disclosure, a first file in a Proto format for interface description is first converted into a second file in a target format, so as to perform subsequent data analysis through a language (e.g., Python) in the target format. And then, analyzing the mapping relation between the first file and the corresponding second file to obtain class description information and nesting relation information. Further, target parameters are determined according to the class description information and the nesting relation information, and a test case of the interface is generated according to the determined target parameters. The technical scheme can be applied to a background interface project defined by Proto, can replace a part for manually analyzing a Proto file and extracting interface parameters, and meanwhile, batch API (application program interface) interface test cases are automatically generated, so that the wrong debugging time caused by parameter analysis errors when case scripts are compiled is avoided, and the interface test efficiency is further improved.
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 disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty.
In the drawings:
FIG. 1 is a schematic diagram illustrating a system architecture of an exemplary application environment to which the test case generation method and apparatus of an interface according to an embodiment of the present disclosure may be applied;
FIG. 2 schematically illustrates a flow diagram of a method for generating test cases for an interface according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a relationship diagram between a first file and a second file according to an embodiment of the present disclosure;
FIG. 4 schematically illustrates a flow chart of a method of determining class description information and nesting relationships of an interface according to an embodiment of the present disclosure;
FIG. 5 schematically illustrates a flow diagram of a method of determining a target class according to an embodiment of the present disclosure;
FIG. 6 schematically illustrates a flow chart of a method of determining a target parameter of an interface according to an embodiment of the present disclosure;
FIG. 7 schematically illustrates a flow diagram of a method for generating test cases for an interface according to another embodiment of the present disclosure;
fig. 8 is a block diagram schematically illustrating a device for generating a test case of an interface in an exemplary embodiment of the present disclosure; and the number of the first and second groups,
fig. 9 shows a schematic structural diagram of an electronic device in an exemplary embodiment of the present disclosure.
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 disclosure. One skilled in the relevant art will recognize, however, that the subject matter of the present disclosure 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 disclosure.
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 flow charts shown in the drawings are merely illustrative 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.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism and an encryption algorithm. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include: the system comprises a block chain bottom layer platform, a platform product service layer and an application service layer.
The block chain underlying platform can comprise processing modules such as user management, basic service, intelligent contract and operation monitoring. The user management module is responsible for identity information management of all blockchain participants, and comprises public and private key generation maintenance (account management), key management, user real identity and blockchain address corresponding relation maintenance (authority management) and the like, and under the authorization condition, the user management module supervises and audits the transaction condition of certain real identities and provides rule configuration (wind control audit) of risk control; the basic service module is deployed on all block chain node equipment and used for verifying the validity of the service request, recording the service request to storage after consensus on the valid request is completed, for a new service request, the basic service firstly performs interface adaptation analysis and authentication processing (interface adaptation), then encrypts service information (consensus management) through a consensus algorithm, transmits the service information to a shared account (network communication) completely and consistently after encryption, and performs recording and storage; the intelligent contract module is responsible for registering and issuing contracts, triggering the contracts and executing the contracts, developers can define contract logics through a certain programming language, issue the contract logics to a block chain (contract registration), call keys or other event triggering and executing according to the logics of contract clauses, complete the contract logics and simultaneously provide the function of upgrading and canceling the contracts; the operation monitoring module is mainly responsible for deployment, configuration modification, contract setting, cloud adaptation in the product release process and visual output of real-time states in product operation, such as: alarm, monitoring network conditions, monitoring node equipment health status, and the like.
The platform product service layer provides basic capability and an implementation framework of typical application, and developers can complete block chain implementation of business logic based on the basic capability and the characteristics of the superposed business. The application service layer provides the application service based on the block chain scheme for the business participants to use.
Fig. 1 is a schematic diagram illustrating a system architecture of an exemplary application environment to which the test case generation method and apparatus of an interface according to the embodiment of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server 105. Any one of the terminal devices 101, 102, and 103 and the server 105 may be used as a block link point device in the block chain. As is exemplary. The method for generating the test case of the interface provided by the disclosure can be executed by any block chain link point, and the generated test case can be stored in the block chain.
In particular, the network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few. The terminal devices 101, 102, 103 may be various electronic devices having a display screen, including but not limited to desktop computers, portable computers, smart phones, tablet computers, and the like. It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation. For example, the server 105 may be a server cluster composed of a plurality of servers.
The method for generating the test case of the interface provided by the embodiment of the disclosure can be executed by any block chain node. For example, the test case may be executed by the service end 105 using a block chain node, and accordingly, the device for generating the test case of the interface is generally disposed in the service end 105. However, it is easily understood by those skilled in the art that the method for generating the test case of the interface provided in the embodiment of the present disclosure may also be executed by other block chain nodes, such as the terminal devices 101, 102, and 103, and correspondingly, the device for generating the test case of the interface may also be disposed in the terminal devices 101, 102, and 103, which is not particularly limited in this exemplary embodiment.
For example, in an exemplary embodiment, it may be that the terminal device 101, 102, 103 obtains a first file in Proto format for interface description and sends the first file to the server 105. Thus, the server 105 converts the first file in the Proto format for the interface description into a second file in the target format; then, the server 105 analyzes the mapping relationship between the first file and the second file to obtain class description information and nesting relationship information. Further, the server 105 determines a target parameter according to the class description information and the nesting relation information; finally, the server 105 generates a test case of the interface according to the target parameters.
Exemplarily, the generated test cases of the interface are stored in a block chain in a distributed manner, so that the usability of the test cases is improved, and the interface test efficiency is improved.
For example, the server 105 may further send the test case of the interface to the terminal devices 101, 102, and 103, so that the user may perform the interface test through the terminal devices 101, 102, and 103.
In another related technology, a Protobuf packet transceiver interface is automatically generated according to Python Protobuf, and an interface name and a parameter name are obtained through a dir content function to produce a test case. However, in the generation scheme of the test case provided by the related art, only the built-in function dir content function is used to obtain the parameter, which may result in that the complex interface parameter cannot be obtained, for example: (1) the structure body of the Message type of the interface cannot be acquired to define the embedded structure body; (2) the modification options of the interface Required, Optional and replayed cannot be obtained; (3) when the parameter of the unavailable interface is an enumeration type, enumerating options and attribute values.
The method and the device for generating the test case of the interface, the computer storage medium and the electronic device provided by the technical scheme can solve one or more problems in the related art at least to a certain extent. The following first describes in detail an embodiment of a method for generating a test case of an interface provided by the present disclosure:
fig. 2 schematically shows a flowchart of a method for generating a test case of an interface according to an embodiment of the present disclosure. Specifically, referring to fig. 2, the embodiment shown in the figure includes:
step S210, converting the first file in the Proto format for interface description into a second file in a target format;
step S220, analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information;
step S230, determining target parameters according to the class description information and the nesting relation information; and the number of the first and second groups,
step S240, generating a test case of the interface according to the target parameters.
The technical scheme provided by the embodiment shown in fig. 2 can be applied to a background interface project defined by Proto, can replace a part for manually analyzing a Proto file and extracting interface parameters, and can automatically generate batch API interface test cases, thereby avoiding wrong debugging time caused by parameter analysis errors when case scripts are compiled, and further improving interface testing efficiency.
The following detailed description of the steps of the embodiment shown in fig. 2 is provided:
in an exemplary embodiment, in step S210, the interface description file (i.e., the first file in Proto format) is converted into the second file in target format. In this embodiment, the data analysis is performed by using Python to obtain the test case, so that the target format in this embodiment may use Python. Then in this embodiment, the second file is in Python format, which is exemplified by:
the conversion of the source file (i.e., the above-mentioned first file) into the second file, i.e., protocol./xxx. proto — Python _ out./, is realized through a Python library, so that the first file of the source code xx.proto is converted into the second file xx _ pb2. py.
Specifically, the data types in the first file in the Proto format can be divided into two major categories. The first type is a composite data type, comprising: an enumeration type and a Message (Message) type; the second type is a standard data type, including: integer, floating point, and string, etc.
In addition, the data type also comprises modifiers:
needs to be assigned and cannot be null, otherwise the Message is considered as 'uniinized'. In addition, the "Required" field is not different from the "Optional" field.
Optional fields may or may not be assigned. If not, a default value is assigned.
And thirdly, Repeated, wherein the field can be Repeated for any times. The order of the repeated data is stored in the Protocol buffer, and the field is thought to be an array capable of automatically setting the size.
In an exemplary embodiment, fig. 3 schematically illustrates a relationship diagram between a first file and a second file according to an embodiment of the disclosure. Specifically, referring to fig. 3, part 310 is an interface description file, i.e. a first file in Proto format, and part 320 is a second file in Python format corresponding to part 310.
In an exemplary embodiment, in step S220, the mapping relationship between the first file and the second file is parsed to obtain the class description information and the nesting relationship information.
Specifically, fig. 4 schematically shows a flowchart of a method for determining class description information and nesting relation of an interface according to an embodiment of the present disclosure, which may be a specific implementation manner of step 220. The embodiment shown in fig. 4 is explained below with reference to fig. 3:
in step S410, a first type description of the target format is determined according to the message structure of the first file.
Exemplarily, referring to fig. 3, the structural body 311 of the portion 310 is specifically:
Figure BDA0002233113280000091
Figure BDA0002233113280000101
the structural body 311 may be determined to be a Message type structural body by the keyword Message.
In an exemplary embodiment, the attribute and method of obtaining the structure 311 by the Descriptor are realized by converting the first file into the second file of the target format. Illustratively, converting 310 the Message type structure 311 results in 320: descriptor and description information 321, and further includes a Descriptor FieldDescriptor 322 for each field in the structure 311. Specifically, the descriptor FieldDescriptor 322 of each Field includes the description information 323 of the Field: field name field type and field options.
Therefore, the second file generated by conversion can obtain the information contained in the Message type structure in the interface description file.
In step S420, the second class description of the target format and the associated file class description are determined according to the enumeration structure of the first file.
Illustratively, referring again to fig. 3, portion 310 of structure 314 is specifically:
Figure BDA0002233113280000102
the structural body 314 may be determined to be an enumeration type structural body by the keyword enum.
In an exemplary embodiment, the attribute and method of obtaining the above-described structure 314 by the descriptor enum descriptor are realized by converting the first file into the second file of the target format. For example, converting the enumerated types of structures 314 in part 310 results in part 320: the enum descriptor and the description information 326 further include a descriptor enum Value descriptor 327 for each enumerated Value (Value) in the structure 314. Specifically, each enum Value descriptor 327 includes Value description information 328: enumerated items and enumerated values.
Therefore, the second file generated by conversion can acquire information contained in the enumerated structure body in the interface description file.
In step S430, the field keyword described by the first type is analyzed to determine the nesting relationship information of the message structure, and the field keyword described by the associated file type is analyzed to determine the nesting relationship information of the associated file in the enumeration structure.
In an exemplary embodiment, whether a Message type structure, an enumeration type structure, or a structure included in an enumeration item may include a nested relationship. The following description takes the example of obtaining the nesting relationship in the structure of the Message type in the interface description file as an example:
illustratively, referring again to fig. 3, the structural body 313 of the portion 310 is specifically:
Figure BDA0002233113280000111
first, it can be determined that the structure is a Message type structure by a keyword Message. In addition, the structure can be determined to be a nested structure by the replicated DataField, and has a nested relationship with the structure 311; the structure can also be determined to be a nested structure by the replicated DataInfo, and has a nested relationship with the structure 312.
In an exemplary embodiment, the determination of the nesting relationship is accomplished by converting the first file to a second file in a target format. Illustratively, referring to 325 in the converted second file shown in FIG. 3: fields _ by _ name [ 'fields' ]. Message _ type ═ DATAFIELD
Fields _ by _ name [ ' data _ info ' ]. Message _ type ═ DATAINFO '. Thus, the nesting relationship shown by the Message type structure 313 in the interface description file is obtained.
Therefore, the second file generated by conversion can acquire the nesting relation contained in each structure body in the interface description file.
In an exemplary embodiment, referring to fig. 3, structure 312 is a twice nested structure. Specifically, the method comprises the following steps:
“Message DataInfo{
Optional string id=1;
Optional int32 ret=2;
Repeated DataField fields=3;
}”
first, it can be determined that the structure is a Message structure by a keyword Message. In addition, the structure can be determined to be a nested structure by the replicated DataField, and has a nested relationship with the structure 311.
Referring to embodiments with respect to structure 314, the determination of the nesting relationship described above is achieved by converting a first file to a second file in a target format. Illustratively, referring to 324 in the converted second file shown in FIG. 3: fields _ by _ name [ 'fields' ], Message _ type ═ DATAFIELD ". Thus, the nesting relationship shown by the Message type structure 312 in the interface description file is obtained.
Through the embodiments shown in fig. 3 and 4, the attribute and method information of each structural body in the interface description file can be acquired. The test cases will be determined by processing the acquired information as follows.
In an exemplary embodiment, fig. 5 schematically illustrates a flow chart of a method of determining a target class according to an embodiment of the present disclosure.
Step S510, acquiring the name of an interface, and filtering out a target class according to the interface name; and the number of the first and second groups,
step S520, analyzing the mapping relationship between the first file and the second file to obtain class description information and nesting relationship information about the target class.
In an exemplary embodiment, invalid classes (structures) are removed in order to improve the efficiency of parsing the structures. In this embodiment, the class of the request type is used as the valid class, and other classes are screened out. Illustratively, classes of request types are: the structures 313 "Message GetReq { … … }" and Message ColumnOpReq { … … } in fig. 3; while classes of the return type (e.g., Message ColumnOpResp (… …)) are useless for interface test requests and will be deleted.
If the request class (i.e., the target class) that is valid for the interface test request is determined by the present embodiment, in step S230, the target parameter is determined according to the class description information of the target class and the nesting relationship information of the target class.
Specifically, fig. 6 schematically shows a flowchart of a method for determining a target parameter of an interface according to an embodiment of the present disclosure, which may be a specific implementation manner of step 230. Referring to fig. 6, the embodiment shown in this figure includes steps S610-S640.
In step S610, it is determined whether the current processing class is a nested structure according to the nesting relationship information.
In this embodiment, different processing is performed according to whether the current processing class is a nested structure (i.e., whether the current processing class includes nested relationship information). Specifically, the method comprises the following steps:
if the current processing class is a nested structure, executing step S620 to step S640:
in step S620, determining a next processing class according to the nesting relationship information;
in step S630, extracting a data type dictionary and a modified label dictionary for the next processing class by regular expression;
in step S640, a target parameter of the next processing class is determined according to the value of the data type dictionary and the value of the modified tag dictionary.
Secondly, if the current processing class is not a nested structure, directly executing step S630 and step S640:
in step S630, extracting a data type dictionary and a modified label dictionary about the current processing class by a regular expression;
in step S640, a target parameter of the current processing class is determined according to the value of the data type dictionary and the value of the modified label dictionary.
In an exemplary embodiment, fig. 7 schematically shows a flowchart of a method for generating a test case of an interface according to another embodiment of the present disclosure, and the following detailed description of each step is continued.
In step S71, a request interface name in the second file is obtained through a dir () built-in function, and a name list is returned; in step S72, the pb2.py file is read and processed, the Descriptor and the enum Descriptor are extracted, and the description content list is returned; in step S73, extracting and decomposing the Descriptor and the enum Descriptor description content list through the regular expression, and returning to the dictionary; illustratively, the dictionary specifically includes: a data type dictionary of classes and a modifier label dictionary.
In an exemplary embodiment, the attribute values of the data type dictionary include: 1 (for double), 3 (for int64), 4 (for unit64), 5 (for int32), 13 (for uint32), 9 (for string), 11 (for string) and 14 (for enum).
In an exemplary embodiment, the property values of the modified tag dictionary include: 3 (representing repaired), 1 (representing Optional), and the like.
In step S741, a request class description is filtered out according to the interface name; alternatively, in step S742, the request class description is excluded from the interface name list. In this embodiment, the efficiency of analyzing the structure is improved by removing the class (structure) that is not effective for the interface test.
In step S75, the nesting relationship of the structure is extracted from the pb2.py file by the field key, and the nesting relationship list is returned.
In step S76, a determination is made based on the attribute value of the modifier label dictionary. The following conditions can be specifically included:
in step S771, if the attribute value is 3, it indicates that the modifier of the field is replied, and further sets the assignment in a list form, such as: a list type.
In step S772, if the attribute value is 1, the modifier of the field is Optional, which indicates that the field is a parameter to be selected and filled.
In step S78, a determination is made based on the attribute value of the data type. The following situations can be specifically included:
in step S791, if the attribute value of the data type dictionary is 14, which indicates that the data type dictionary belongs to the enumeration type, the assignment process is performed by using a processing function of the enumeration type. Illustratively, enumerated options and values are given.
In step S792, if the attribute value of the data type dictionary is 1/3/4/5/13/9, indicating that the attribute belongs to double/int64/unit64/int32/uint32/string (i.e., base type), the default value is assigned. For example: if the attribute value of the data type dictionary is 9, the parameter name is directly assigned to "" 1 "".
In step S793, if the attribute value of the data type dictionary is 11, which indicates that the data type dictionary belongs to the structure, the assignment process is performed by using the processing function of the structure. Illustratively, the nesting relationship will be looked up to determine the next class description to be processed, and a dictionary of the class. Further, steps S76 and S78 are repeatedly performed.
Through the technical solution provided by the embodiment shown in fig. 7, the target parameters related to the target class are determined, and further, in step S240, the test case of the interface is generated according to the target parameters.
In an exemplary embodiment. Firstly, a test case template is obtained, and then the interface name and the target parameters of the target class are filled into the test case template to obtain the test case of the interface.
Specifically, the interface name and the target parameter are used as JSON objects, and the JSON objects are rendered into the test case template, so that the interface name and the target parameter are filled into the test case template, and the test case of the interface is obtained. Illustratively, the contents of the JSON object are filled into a test case Template by using a Template function of a string module of Python, so as to generate a test case of the interface.
The method for generating the test case of the interface can be applied to background interface items defined by Proto, can replace a part for manually analyzing a Proto file and extracting interface parameters, and can automatically generate batch API (application program interface) test cases, thereby avoiding wrong debugging time caused by parameter analysis errors when case scripts are compiled, and further improving the interface test efficiency. The technical scheme can be executed by the block chain link points, and the generated test cases of the interface can be stored in the block chain in a distributed mode. Therefore, the usability of the test case is improved, and the interface test efficiency is further improved.
Those skilled in the art will appreciate that all or part of the steps for implementing the above embodiments are implemented as computer programs executed by a processor (including a CPU and a GPU). When executed by the CPU, performs the functions defined by the above-described methods provided by the present disclosure. The program may be stored in a computer readable storage medium, which may be a read-only memory, a magnetic or optical disk, or the like.
Furthermore, it should be noted that the above-mentioned figures are only schematic illustrations of the processes involved in the methods according to exemplary embodiments of the present disclosure, 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.
The following describes embodiments of a device for generating a test case of an interface according to the present disclosure, which can be used to execute the method for generating a test case of an interface according to the present disclosure.
Fig. 8 is a block diagram schematically illustrating a device for generating a test case of an interface in an exemplary embodiment of the present disclosure. As shown in fig. 8, the apparatus 800 for generating a test case of the interface includes: a conversion module 801, a parsing module 802, a parameter determination module 803, and a test case generation module 804. Wherein:
the above-mentioned conversion module 801 is configured to: converting a first file in a Proto format for interface description into a second file in a target format; the parsing module 802 is configured to: analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information; the above-mentioned parameter determination module 803 is configured to: determining target parameters according to the class description information and the nesting relation information; the test case generation module 804 is configured to: and generating a test case of the interface according to the target parameters.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parsing module 802 is specifically configured to:
determining a first type description of the target format according to the message structure body of the first file; determining a second type description and an associated file type description of the target format according to the enumeration structure of the first file; and analyzing the field keywords described by the first type to determine the nesting relation information of the message structure, and analyzing the field keywords described by the associated file type to determine the nesting relation information of the associated file in the enumeration structure.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parameter determining module 803 is specifically configured to:
judging whether the current processing class is a nested structure body or not according to the nesting relation information; if the current processing class is not a nested structure, then:
extracting a data type dictionary and a modified label dictionary related to the current processing class through a regular expression; and determining the target parameters of the current processing class according to the values of the data type dictionary and the values of the modified label dictionary.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parameter determining module 803 is specifically further configured to:
if the current processing class is a nested structure, then:
determining the next processing class according to the nesting relation information; extracting a data type dictionary and a modified label dictionary about the next processing class through a regular expression; and determining the target parameter of the next processing class according to the value of the data type dictionary and the value of the modified label dictionary.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the parsing module 802 is further specifically configured to:
acquiring the name of an interface, and filtering a target class according to the interface name; and analyzing the mapping relation between the first file and the second file to obtain the class description information and the nesting relation information of the target class.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module 804 is specifically configured to:
and acquiring a test case template, and filling the interface name and the target parameters of the target class into the test case template to obtain the test case of the interface.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module 804 is further specifically configured to:
and generating a test case of the interface according to the target parameters, and storing the test case into a block chain.
In an exemplary embodiment of the present disclosure, based on the foregoing scheme, the test case generation module 804 is further specifically configured to:
and taking the interface name and the target parameter as JSON objects, and rendering the JSON objects to the test case template.
The specific details of each unit in the device for generating a test case of an interface are described in detail in the method for generating a test case of an interface corresponding to fig. 2 to 7 in the specification, and therefore are not described again here.
FIG. 9 illustrates a schematic structural diagram of a computer system suitable for use in implementing the electronic device of an embodiment of the present disclosure.
It should be noted that the computer system 900 of the electronic device shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of the application of the embodiments of the present disclosure.
As shown in fig. 9, computer system 900 includes a processor 901 (including a Graphics Processing Unit (GPU), a Central Processing Unit (CPU)), which can perform various appropriate actions and processes according to a program stored in a Read-Only Memory (ROM) 902 or a program loaded from a storage portion 908 into a Random Access Memory (RAM) 903, and in the RAM 903, various programs and data necessary for system operation.
The following components are connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output portion 907 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage portion 908 including a hard disk and the like; and a communication section 909 including a Network interface card such as a Local Area Network (LAN) card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
In particular, the processes described below with reference to the flowcharts may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The computer program, when executed by the processor (CPU or GPU)901, performs various functions defined in the system of the present application.
It should be noted that the computer readable medium shown in the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer 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 of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an Erasable Programmable Read-Only Memory (EPROM), a 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.
In the present disclosure, a computer 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. In contrast, in the present disclosure, a computer-readable signal medium may include a propagated data signal with computer-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 computer readable signal medium may also be any computer readable medium that is not a computer 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 computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures.
For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware, and the described units may also be disposed in a processor. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
As another aspect, the present application also provides a computer-readable medium, which may be contained in the electronic device described in the above embodiments; or may be separate and not incorporated into the electronic device. The computer readable medium carries one or more programs which, when executed by an electronic device, cause the electronic device to implement the method described in the above embodiments.
For example, the electronic device may implement the following as shown in fig. 2: step S210, converting the first file in the Proto format for interface description into a second file in a target format; step S220, analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information; step S230, determining target parameters according to the class description information and the nesting relation information; and step S240, generating a test case of the interface according to the target parameters.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
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 disclosure 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 touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure 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 present disclosure is limited only by the appended claims.

Claims (8)

1. A method for generating a test case of an interface is characterized by comprising the following steps:
converting a first file in a Proto format for interface description into a second file in a target format;
analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information;
judging whether the current processing class is a nested structure according to the nesting relation information;
if the current processing class is not a nested structure, extracting a data type dictionary and a modified label dictionary related to the current processing class through a regular expression; determining a target parameter of the current processing class according to the value of the data type dictionary and the value of the modified label dictionary;
if the current processing class is a nested structure, determining a next processing class according to the nested relation information; extracting a data type dictionary and a modified label dictionary about the next processing class through a regular expression; determining a target parameter of the next processing class according to the value of the data type dictionary and the value of the modified label dictionary;
and generating a test case of the interface according to the target parameters.
2. The method for generating the test case of the interface according to claim 1, wherein the analyzing a mapping relationship between the first file and the second file to obtain class description information and nesting relationship information includes:
determining a first type description of the target format according to the message structure body of the first file;
determining a second class description and an associated file class description of the target format according to the enumeration structure of the first file;
and analyzing the field keywords described by the first type to determine the nesting relation information of the message structure, and analyzing the field keywords described by the associated file type to determine the nesting relation information of the associated file in the enumeration structure.
3. The method for generating the test case of the interface according to claim 1 or 2, wherein the analyzing the mapping relationship between the first file and the second file to obtain the class description information and the nesting relationship information includes:
acquiring the name of an interface, and filtering a target class according to the interface name;
and analyzing the mapping relation between the first file and the second file to obtain the class description information and the nesting relation information of the target class.
4. The method according to claim 3, wherein the generating the test case of the interface according to the target parameter includes:
and acquiring a test case template, and filling the interface name of the target class and the target parameters into the test case template to obtain the test case of the interface.
5. The method for generating the test case of the interface according to claim 1, wherein the generating the test case of the interface according to the target parameter includes:
and generating a test case of the interface according to the target parameters, and storing the test case into a block chain.
6. An apparatus for generating a test case of an interface, the apparatus comprising:
a conversion module configured to: converting a first file in a Proto format for interface description into a second file in a target format;
a parsing module configured to: analyzing the mapping relation between the first file and the second file to obtain class description information and nesting relation information;
a parameter determination module configured to: judging whether the current processing class is a nested structure according to the nesting relation information; if the current processing class is not a nested structure, extracting a data type dictionary and a modified label dictionary related to the current processing class through a regular expression; determining a target parameter of the current processing class according to the value of the data type dictionary and the value of the modified label dictionary; if the current processing class is a nested structure, determining a next processing class according to the nested relation information; extracting a data type dictionary and a modified label dictionary about the next processing class through a regular expression; determining a target parameter of the next processing class according to the value of the data type dictionary and the value of the modified label dictionary;
a test case generation module configured to: and generating a test case of the interface according to the target parameters.
7. A computer storage medium, on which a computer program is stored, the computer program, when executed by a processor, implementing a method of generating test cases for an interface according to any one of claims 1 to 5.
8. An electronic device, characterized in that the electronic device comprises:
one or more processors;
a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the method for generating a test case for an interface according to any one of claims 1 to 5.
CN201910974309.3A 2019-10-14 2019-10-14 Method, device, medium and equipment for generating test case of interface Active CN110781082B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910974309.3A CN110781082B (en) 2019-10-14 2019-10-14 Method, device, medium and equipment for generating test case of interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910974309.3A CN110781082B (en) 2019-10-14 2019-10-14 Method, device, medium and equipment for generating test case of interface

Publications (2)

Publication Number Publication Date
CN110781082A CN110781082A (en) 2020-02-11
CN110781082B true CN110781082B (en) 2022-05-20

Family

ID=69385359

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910974309.3A Active CN110781082B (en) 2019-10-14 2019-10-14 Method, device, medium and equipment for generating test case of interface

Country Status (1)

Country Link
CN (1) CN110781082B (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111399900B (en) * 2020-03-10 2023-04-07 山东汇贸电子口岸有限公司 API document automatic generation method and system based on python and regular expression
CN113495829A (en) * 2020-03-20 2021-10-12 北京海致星图科技有限公司 Automatic interface testing method and system
CN113495831B (en) * 2020-04-03 2024-05-31 卫宁健康科技集团股份有限公司 Method, system, equipment and medium for generating test case based on keywords
CN111627171A (en) * 2020-04-28 2020-09-04 深圳壹账通智能科技有限公司 Test message conversion method, device, equipment and medium of ATMP system
CN111917729B (en) * 2020-07-09 2023-04-07 财付通支付科技有限公司 Dynamic injection test method and device and related equipment
CN112202633B (en) * 2020-09-24 2022-07-12 成都质数斯达克科技有限公司 Block chain network testing method and device, electronic equipment and readable storage medium
CN113778779B (en) * 2020-11-18 2024-04-16 北京京东拓先科技有限公司 Monitoring method, system, device, electronic equipment and medium of data interface
CN112464591B (en) 2020-11-19 2022-10-18 苏州浪潮智能科技有限公司 Multi-port nested model connection analysis method and medium
CN112328419B (en) * 2020-11-27 2024-07-02 北京字节跳动网络技术有限公司 Test case generation method and device of remote procedure call interface, storage medium and electronic equipment
CN112650533B (en) * 2020-12-22 2024-03-19 深圳前海微众银行股份有限公司 Interface document generation method and device and terminal equipment
CN112948252A (en) * 2021-03-09 2021-06-11 上海万向区块链股份公司 Visual use case management method, system and medium based on alliance chain storage
CN113704095A (en) * 2021-08-08 2021-11-26 中国航空工业集团公司沈阳飞机设计研究所 Automatic generation method and device for automatic interface test case
CN114461188A (en) * 2021-12-30 2022-05-10 奇安信科技集团股份有限公司 API code automatic generation method, device, equipment, medium and program
CN114816246B (en) * 2022-04-12 2024-09-13 盐城天眼察微科技有限公司 Processing method and device for Proto file
CN115659941B (en) * 2022-11-11 2023-07-21 摩尔线程智能科技(北京)有限责任公司 File generation method and device suitable for multiple types of interfaces

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104866426A (en) * 2015-05-28 2015-08-26 华北计算技术研究所 Software test integrated control method and system
CN105760534A (en) * 2016-03-10 2016-07-13 上海晶赞科技发展有限公司 User-defined serializable data structure, hadoop cluster, server and application method thereof
CN106648945A (en) * 2016-09-30 2017-05-10 北京金山安全软件有限公司 Interface data testing method and device and electronic equipment
CN108108162A (en) * 2016-11-24 2018-06-01 腾讯科技(深圳)有限公司 Application programming interface generation method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10977434B2 (en) * 2017-07-11 2021-04-13 Asana, Inc. Database model which provides management of custom fields and methods and apparatus therfor

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104866426A (en) * 2015-05-28 2015-08-26 华北计算技术研究所 Software test integrated control method and system
CN105760534A (en) * 2016-03-10 2016-07-13 上海晶赞科技发展有限公司 User-defined serializable data structure, hadoop cluster, server and application method thereof
CN106648945A (en) * 2016-09-30 2017-05-10 北京金山安全软件有限公司 Interface data testing method and device and electronic equipment
CN108108162A (en) * 2016-11-24 2018-06-01 腾讯科技(深圳)有限公司 Application programming interface generation method and device

Also Published As

Publication number Publication date
CN110781082A (en) 2020-02-11

Similar Documents

Publication Publication Date Title
CN110781082B (en) Method, device, medium and equipment for generating test case of interface
US11562293B2 (en) Adaptation of machine learning algorithms
US11823017B2 (en) Interoperation of machine learning algorithms
CA3046247C (en) Data platform for automated data extraction, transformation, and/or loading
US11698818B2 (en) Load balancing of machine learning algorithms
CN112104709B (en) Intelligent contract processing method, device, medium and electronic equipment
US20210142221A1 (en) Autonomous logic modules
CN112187558B (en) Data verification method and device and electronic equipment
CN110990053A (en) Method for creating and using machine learning scheme template and device
CN113238929B (en) Code testing method and device based on Mock data, electronic equipment and storage medium
WO2023029509A1 (en) Dynamic service publishing method and apparatus, and electronic device and storage medium
CN113238740A (en) Code generation method, code generation device, storage medium, and electronic apparatus
CN112328551A (en) Medical data analysis method, device, medium, and electronic device
US20110055373A1 (en) Service identification for resources in a computing environment
CN114138679A (en) Test data construction method and device, computer readable medium and electronic equipment
CN114491064A (en) Internet of things platform construction method and device, storage medium and terminal
CN114816361A (en) Method, device, equipment, medium and program product for generating splicing project
Rinner et al. Creating ISO/EN 13606 archetypes based on clinical information needs
CN115292516A (en) Block chain-based distributed knowledge graph construction method, device and system
CN115016754A (en) Method and device for synchronously displaying pages among devices, electronic device and medium
CN113053531B (en) Medical data processing method, medical data processing device, computer readable storage medium and equipment
CN107402565A (en) A kind of method and device for specification Internet of things hardware sensing layer feedback information
Brown et al. The architecture and implementation of a distributed computer integrated construction environment
Sun et al. Research on Development and Integration of Artificial Intelligence Aided Diagnosis System
CN114416575A (en) Method, device and equipment for generating Mock data and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40022070

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant