CN113778846A - Method and apparatus for generating test data - Google Patents

Method and apparatus for generating test data Download PDF

Info

Publication number
CN113778846A
CN113778846A CN202011371263.5A CN202011371263A CN113778846A CN 113778846 A CN113778846 A CN 113778846A CN 202011371263 A CN202011371263 A CN 202011371263A CN 113778846 A CN113778846 A CN 113778846A
Authority
CN
China
Prior art keywords
data
template
type
meta
placeholder
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
CN202011371263.5A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202011371263.5A priority Critical patent/CN113778846A/en
Publication of CN113778846A publication Critical patent/CN113778846A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING; 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/33Querying
    • G06F16/3331Query processing
    • G06F16/334Query execution
    • G06F16/3344Query execution using natural language analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/36Creation of semantic tools, e.g. ontology or thesauri
    • G06F16/374Thesaurus

Abstract

Embodiments of the present disclosure disclose methods and apparatus for generating test data. One embodiment of the method comprises: acquiring parameter structure information and a target data format of an interface to be tested; generating meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data comprises data type information and reference relation information; determining a template of the interface to be tested based on the meta-structure data, the template including placeholders that match the meta-structure data; generating initial test data based on the template: determining a data generation rule corresponding to each placeholder in the template based on the corresponding relation between the preset placeholder and the data generation rule; generating data corresponding to each placeholder based on the data generation rule corresponding to each placeholder; replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data; and converting the data format of the initial test data into a target data format to obtain target test data. Test data may be automatically generated.

Description

Method and apparatus for generating test data
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a method and a device for generating test data.
Background
The application of various software in daily life of people is more extensive, and along with the change from an integral architecture of the application to a micro-service architecture, the application is divided into a plurality of services capable of running independently, wherein the interface of each service is related to whether the application can run normally, so that the test of the interface is an important ring in application development.
In the related art, the method for acquiring test data required by the interface test generally includes the following steps: test data are manually compiled by a tester; analog data is generated by writing some expression, such as: js; or forming a data set through data acquisition or manual entry, and selecting test data from the data set based on a preset rule.
Disclosure of Invention
Embodiments of the present disclosure propose methods and apparatuses for generating test data.
In a first aspect, an embodiment of the present disclosure provides a method for generating test data, the method including: acquiring parameter structure information and a target data format of an interface to be tested, wherein the parameter structure information comprises parameter entering structure information and parameter exiting structure information; generating meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data comprises data type information of the interface to be tested and reference relation information of each type of data for referencing other types of data; determining a template of the interface to be tested based on the meta-structure data, the template including placeholders that match the meta-structure data; generating initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on the corresponding relation between the preset placeholder and the data generation rule; generating data corresponding to each placeholder based on the data generation rule corresponding to each placeholder; replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data; and converting the data format of the initial test data into a target data format to obtain target test data.
In some embodiments, the template is obtained via the following template generation steps: determining a parameter recursion generation structure of each data type in the data type information of the meta-structure data based on the reference relation information of the meta-structure data, wherein the parameter recursion generation structure represents the structure of the data type; determining a placeholder matched with each data type in the data type information of the meta-structure data; and recursively generating a structure based on the parameters of the data types, and combining the placeholders matched with the data types in the data type information of the meta-structure data into a template.
In some embodiments, determining a template for the interface to be tested based on the meta structure data comprises: retrieving a preset template database based on the meta-structure data; if a template corresponding to the meta-structure data exists in the template database, determining the template as a template of the interface to be tested; and if the template corresponding to the meta-structure data does not exist in the template database, executing a template generation step to generate a template of the interface to be tested.
In some embodiments, the meta structure data further includes a field name of the field type data and a value type and a value range of the base type data; and determining placeholders matched with the data types in the data type information of the meta-structure data, wherein the placeholders comprise: determining dictionary words matched with field names of the field type data and/or value types and value ranges of the basic type data from a preset dictionary library based on a preset matching strategy in response to the fact that the data type information of the meta structure data comprises the field type data and/or the basic type data; determining placeholders corresponding to dictionary words based on the corresponding relation between preset dictionary words and the placeholders; and determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
In some embodiments, the method further comprises: recognizing a construction rule of the dictionary words corresponding to the placeholders by adopting a pre-trained word generation model, and generating new dictionary words based on the recognized construction rule of the dictionary words; establishing a corresponding relation between the new dictionary words and the placeholders; and storing the new dictionary words into the dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
In some embodiments, generating initial test data based on the template further comprises: and if the data generation rule corresponding to the placeholder does not exist, taking the placeholder as the data corresponding to the placeholder.
In a second aspect, an embodiment of the present disclosure further provides an apparatus for generating test data, the apparatus including: the information acquisition unit is configured to acquire parameter structure information and a target data format of the interface to be tested, wherein the parameter structure information comprises parameter entering structure information and parameter exiting structure information; the meta structure data generating unit is configured to generate meta structure data of the interface to be tested based on the parameter structure information, wherein the meta structure data comprises data type information of the interface to be tested and reference relation information of each type of data for referencing other types of data; a template determination unit configured to determine a template of the interface to be tested based on the meta structure data, the template including placeholders that match the meta structure data; an initial data generation unit configured to generate initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on the corresponding relation between the preset placeholder and the data generation rule; generating data corresponding to each placeholder based on the data generation rule corresponding to each placeholder; replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data; and the data format conversion unit is configured to convert the data format of the initial test data into a target data format to obtain target test data.
In some embodiments, the apparatus further comprises a template generation unit configured to: determining a parameter recursion generation structure of each data type in the data type information of the meta-structure data based on the reference relation information of the meta-structure data, wherein the parameter recursion generation structure represents the structure of the data type; determining a placeholder matched with each data type in the data type information of the meta-structure data; and recursively generating a structure based on the parameters of the data types, and combining the placeholders matched with the data types in the data type information of the meta-structure data into a template.
In some embodiments, the template determination unit, by an advancer, is configured to: retrieving a preset template database based on the meta-structure data; if a template corresponding to the meta-structure data exists in the template database, determining the template as a template of the interface to be tested; and if the template corresponding to the meta-structure data does not exist in the template database, executing a template generation step to generate a template of the interface to be tested.
In some embodiments, the meta structure data further includes a field name of the field type data and a value type and a value range of the base type data; and the template generation unit is further configured to: determining dictionary words matched with field names of the field type data and/or value types and value ranges of the basic type data from a preset dictionary library based on a preset matching strategy in response to the fact that the data type information of the meta structure data comprises the field type data and/or the basic type data; determining placeholders corresponding to dictionary words based on the corresponding relation between preset dictionary words and the placeholders; and determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
In some embodiments, the apparatus further comprises a dictionary repository expansion unit configured to: recognizing a construction rule of the dictionary words corresponding to the placeholders by adopting a pre-trained word generation model, and generating new dictionary words based on the recognized construction rule of the dictionary words; establishing a corresponding relation between the new dictionary words and the placeholders; and storing the new dictionary words into the dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
In some embodiments, the initial data generation unit is further configured to: and if the data generation rule corresponding to the placeholder does not exist, taking the placeholder as the data corresponding to the placeholder.
According to the method and the device for generating the test data, the meta-structure data are generated based on the parameter structure information of the interface to be tested, the template of the interface to be tested is determined based on the meta-structure data, then the initial test data are automatically generated based on the template, and the initial test data are converted into the target data format matched with the interface to be tested. The test data with different formats can be automatically generated, and the efficiency of generating the test data is improved.
Drawings
Other features, objects and advantages of the disclosure will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which some embodiments of the present disclosure may be applied;
FIG. 2 is a flow diagram of one embodiment of a method for generating test data according to the present disclosure;
FIG. 3 is a flow chart of one embodiment of a template generation step in a method for generating test data of the present disclosure;
FIG. 4 is a flow diagram for one embodiment of generating dictionary words in a method for generating test data according to the present disclosure;
FIG. 5 is a schematic block diagram illustrating one embodiment of an apparatus for generating test data according to the present disclosure;
FIG. 6 is a schematic structural diagram of an electronic device suitable for use in implementing embodiments of the present disclosure.
Detailed Description
The present disclosure is described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary system architecture 100 of a method for generating test data or an apparatus for generating test data to which embodiments of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing 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 user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or transmit data or the like, e.g. information of the interface to be tested may be transmitted to the server, and generated test data may also be received from the server.
The terminal apparatuses 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, and 103 are hardware, they may be electronic devices with communication functions, including but not limited to smart phones, tablet computers, e-book readers, laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented, for example, as multiple software or software modules to provide distributed services, or as a single software or software module. And is not particularly limited herein.
The server 105 may be a server providing various services, such as a background data server processing information data of the interfaces to be tested uploaded by the terminal devices 101, 102, 103 (e.g. generating test data based on the information of the interfaces to be tested). The background data server can analyze and process the received information of the interface to be tested, then generates test data based on the information of the interface to be tested, and feeds the generated test data back to the terminal equipment.
It should be noted that the method for generating test data provided by the embodiments of the present disclosure may be executed by the terminal devices 101, 102, and 103, or may be executed by the server 105. Accordingly, the means for generating test data may be provided in the terminal devices 101, 102, 103, or in the server 105. And is not particularly limited herein.
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules, for example, to provide distributed services, or as a single piece of software or software module. And is not particularly limited herein.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method for generating test data in accordance with the present disclosure is shown. The method for generating test data comprises the following steps:
step 201, obtaining parameter structure information and a target data format of an interface to be tested, wherein the parameter structure information comprises parameter entering structure information and parameter exiting structure information.
In this embodiment, the interface to be tested may be an interface of a complete application or an interface of one micro service of a plurality of micro services included in one application, according to different application hierarchies, which is not limited in this application.
The parameter structure information represents structure information of request parameters of the interface to be tested, and includes structure information of the entries and the entries, for example, the structure (object or array) of the entries, the type (string type, boolean type or numerical type) of the entries, and the structure and type of the entries. The target data format indicates a format of data that can be input into the interface to be tested, and may be, for example, an XML format, a JS format, or the like.
As an example, the interface to be tested may be an HTTP (hypertext Transfer Protocol) interface in a certain web page, and the executing entity (for example, the server 105 shown in fig. 1) may receive an address of the HTTP interface and then parse the HTTP interface to determine parameter structure information and a target data format of the HTTP interface.
Step 202, generating meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data includes data type information of the interface to be tested and reference relationship information that each type of data references other types of data.
In this embodiment, the meta structure data is used to describe a meta structure of data of the interface to be tested, and the meta structure of the data of the interface to be tested is a data structure of request parameters of the interface to be tested. The data type information of the interface to be tested represents the data type included in the request parameter of the interface to be tested, and the reference relation information represents the structure information of the composite data in the request parameter. For example, if the array data is composite data formed based on KV (Key-Value) data, the reference relationship information of the array data is the array reference KV.
As an example, the execution subject may parse the request parameters of the interface to be tested into a meta structure of a corresponding type based on the parameter structure information of the interface to be tested, and then generate meta structure data based on the meta structure. Meta-structures may include, but are not limited to: array type, KV type, field type, object type, and base type.
The data corresponding to the data expressed as the one-dimensional or multidimensional array type is an array type element structure, and the reference relation information of the array type element structure data is other data types, except field type data, referred by the array type data. For example, if the array type data is constructed based on KV type data, the data type information of the meta structure data includes an array type and a KV type, and the reference relationship information is an array type reference KV type. Further, the array type meta structure data may also include the dimension of the array.
And the meta structure corresponding to the data expressed as the Key-Value structure type is a KV meta structure. For example, if Key is array type data and Value is object type data, the data type information of the KV type meta structure data is: KV type, array type and object type, and the reference relationship information is: key refers to array type, Value refers to object type.
The meta structure corresponding to the data expressed as a field type is a field type meta structure; the element structure corresponding to data of a numerical type, a character string type, a Boolean type or an enumeration type is represented as a basic element structure; the meta structure corresponding to the data representing one object type is an object type meta structure, and since the data of the object type only contains zero or more field type meta structure references, the reference relationship information of the data of the object type meta structure is null or an object type reference field type.
Step 203, determining a template of the interface to be tested based on the meta-structure data, wherein the template comprises a placeholder matched with the meta-structure data.
In this embodiment, the placeholder corresponds to a data type in the meta-structure data, and is used for characterizing a generation rule of the data of the type. Each meta-structure data typically includes one or more matching placeholders, and the template may be a string including all matching placeholders with the meta-structure data, and is used to characterize the generation rules of the test data of the interface to be tested, and the format of the template may be JSON, XML, or the like.
By way of example, the execution body has a placeholder library pre-stored therein, each placeholder in the placeholder library including a placeholder name and a data type to which the placeholder applies. Each type of data type is provided with a default placeholder. As such, the execution body may match placeholders by data type in the meta-structure data. Further, the execution subject may pre-construct a template database, and store the pre-constructed template in the template database based on the correspondence between the meta-structure data and the template, so that the execution subject may retrieve the template corresponding to the meta-structure data in the template database and determine the template as the template of the interface to be tested.
The placeholder may include an identifier, a placeholder name, and a numeric value range, where the identifier is used to distinguish the placeholder from other data, and the placeholder name may represent a content attribute of the data (e.g., a name indicating that the data content corresponding to the placeholder is a name; native indicating that the data corresponding to the placeholder is a natural number). As an example, the request parameters of the interface to be tested include parameters such as name (field type), age (basic type), and gender (KV type), and the data type information of the meta structure data of the interface to be tested includes: the field type, the basic type and the KV type, and the reference relationship information is null. The placeholder matched with the meta-structure data may include "@ name", "@ age", and "@ enum (M, F)", where "@ name" represents that the generation rule of the part of data is a name generation rule, "@ age" represents that the generation rule of the part of data is an age generation rule, and "@ enum (M, F)" represents that the generation rule of the part of data is a gender generation rule, and a value range of the generation rule is M (Male) or F (Female). The template of the interface to be tested can be a character string: "@ name @ age @ enum (M, F)".
With further reference to FIG. 3, FIG. 3 is a flow chart of one embodiment of the template generation step in the method for generating test data of the present disclosure. In this embodiment, the execution subject may generate the template through the process 300 shown in fig. 3, where the process 300 includes the following steps:
step 301, determining a parameter recursive generation structure of each data type in the data type information of the meta-structure data based on the reference relationship information of the meta-structure data, where the parameter recursive generation structure represents the structure of the data type.
In this implementation, the parameter recursion generation structure may characterize the structure of the data by reference relationships between various types of data.
As an example, the execution subject may take a parameter recursive generation structure that acquires various types of meta structures as follows.
The execution main body analyzes the meta structure data, if the meta structure data comprises a number group type meta structure, the execution main body firstly analyzes the dimension structure of the number group type meta structure, then obtains the reference relation between each element in the number group and other types of meta structures, and analyzes the parameter recursion generation structure of the referenced type meta structure to obtain the parameter recursion generation structure (comprising the dimension of the number group and the recursion generation structure of the element) of the number group type meta structure.
If the meta-structure data includes a field type meta-structure, the execution subject first determines whether the field type meta-structure refers to a basic type meta-structure, and if so, obtains a value type and a value range of the basic type meta-structure, and obtains a parameter recursion generation structure (including the value type and the value range of the referred basic type) of the field type meta-structure; if not, directly obtaining the parameter recursion generation structure of the field type element structure.
If the meta-structure data comprises a KV meta-structure, the execution main body firstly acquires the reference relationship of the Key-type meta-structure to reference other types of data, analyzes the parameter recursion generation structure of the other types of meta-structures referenced by the Key-type meta-structure to acquire the parameter recursion generation structure of the Key-type meta-structure, then acquires the reference relationship of the Value-type data to reference other types of data, analyzes the parameter recursion generation structure of the meta-structure referenced by the Value-type meta-structure to acquire the parameter recursion generation structure of the Value-type meta-structure, merges the parameter recursion generation structure of the Key-type meta-structure and the parameter recursion generation structure of the Value-type meta-structure, and can obtain the parameter recursion generation structure of the KV meta-structure.
In a specific example, the elements in the array type data are KV type data, where the Key type meta structure in each element is constructed based on the field type meta structure, and the V type meta structure is constructed based on the basic type data, so that the execution subject can generate the meta structure data, the data type information of the meta structure data is array type, KV type, field type and basic type, the reference relationship information is array type reference KV type, Key reference field type, and Value reference basic type. Then, the executing body may first obtain a parameter recursive generation structure of the array type meta-structure (including the dimension of the array and the referenced KV type meta-structure) according to the parsing step of the array type meta-structure, then acquiring a parameter recursion generation structure (comprising a parameter recursion generation structure of a Key-type element structure and a parameter recursion generation structure of a Value-type element structure) of the KV-type element structure quoted by the array elements according to the analysis step of the KV-type element structure, acquiring a parameter recursion generation structure of a field-type element structure quoted by the Key-type element structure according to the analysis step of the field-type element structure, and acquiring a parameter recursion generation structure (comprising a Value range and a Value type) of the basic type element structure quoted by the Value type element structure according to the analysis step of the basic type element structure, and finally combining the parameter recursion generation structures of all levels according to a hierarchical sequence to obtain the parameter recursion generation structure of the element structure data.
Step 302, determining placeholders matched with the data types in the data type information of the meta-structure data.
In this implementation, each data type corresponds to one or more placeholders to characterize the generation rules for that type of data.
Optionally, the meta structure data further includes a field name of the field type data and a value type and a value range of the basic type data. The execution principal may determine placeholders matching each data type in the data type information of the meta structure data through step 3021, step 3022, and step 3023.
Step 3021, in response to determining that the data type information of the meta structure data includes field type data and/or basic type data, determining dictionary words matched with the field names of the field type data and/or the value types and the value ranges of the basic type data from a preset dictionary library based on a preset matching strategy.
In this implementation, the execution subject may perform matching degree calculation on the field names of the field type data or the value types and value ranges of the basic type data and the dictionary words in the dictionary library to determine the dictionary words matched with the field type data or the basic type data in the meta structure data.
As an example, the field name of the field type data in the meta structure data is "zhangsan", the value type of the basic type data is a natural number, and the value range is greater than or equal to 1, the execution subject may perform matching degree calculation on the dictionary words in the dictionary library by using an N-Gram algorithm, and determine that the dictionary word with the highest matching degree with "zhangsan" is "name", and the dictionary word with the highest matching degree with the basic type data with the value type of the natural number and the value range of greater than or equal to 1 is "stock".
And step 3022, determining placeholders corresponding to the dictionary words based on the preset corresponding relationship between the dictionary words and the placeholders.
In this implementation manner, a corresponding relationship between a dictionary word and a placeholder may be preset, and thus, the execution main body may determine the placeholder corresponding to the dictionary word according to the corresponding relationship.
Continuing with the example in step 3021, the execution principal may determine that the placeholder corresponding to the "name" is "@ name" and the placeholder corresponding to the "stock" is "@ name (1)" based on the correspondence between the dictionary word and the placeholder.
Step 3023, determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
Continuing with the example in step 3021, the execution principal may determine the placeholder corresponding to the field-type data in the meta-structure data as "@ name", and determine the placeholder corresponding to the base-type data as "@ name (1)".
Step 303, generating a structure based on the parameter recursion of each data type, and combining the placeholders matched with each data type in the data type information of the meta-structure data into a template.
In this implementation manner, the placeholder is used to represent a generation rule of one type of data, the parameter recursion generation structure represents a composite reference relationship between various types of data, and the corresponding placeholder is formed into a character string according to the parameter recursion generation structures of the types obtained in step 301, so that the template of the interface to be tested can be obtained. Therefore, the generating rule of the test data represented by the template not only comprises the content of the test data, but also comprises the structure of the test data, so that the authenticity of the test data generated based on the template can be improved.
As a further preferred embodiment of the above implementation, the executing body may determine the template of the interface to be tested by: retrieving a preset template database based on the meta-structure data; if a template corresponding to the meta-structure data exists in the template database, determining the template as a template of the interface to be tested; and if the template corresponding to the meta-structure data does not exist in the template database, executing a template generation step to generate a template of the interface to be tested.
And step 204, generating initial test data based on the template.
In this embodiment, the template represents a generation rule of the test data, and the execution subject may generate the test data of the interface to be tested based on the template. Step 204 further comprises the steps of:
step 2041, based on the correspondence between the preset placeholders and the data generation rules, the data generation rules corresponding to the placeholders in the template are determined.
In this embodiment, each placeholder corresponds to a data generation rule, for example, "@ name" corresponds to a generation rule of a name, and @ name (1) corresponds to a natural number of which the generation rule is greater than or equal to 1. Therefore, the main body is executed to determine the data generation rule corresponding to each placeholder in the template, and the generation rule of the whole test data can be obtained.
Step 2042, based on the data generation rule corresponding to each placeholder, data corresponding to each placeholder is generated.
In this embodiment, the executing subject may use various data generating tools to generate data corresponding to the placeholder based on the data generating rule determined in step 2041.
Optionally, the executing entity may further obtain, for each data generation rule, data that meets the data generation rule from the network, and then store the data into a pre-constructed database, so that the executing entity may directly extract corresponding data from the database according to the data generation rule corresponding to each placeholder in the template determined in step 2041.
And 2043, replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data.
In this embodiment, the initial test data is data generated according to a template and in an unconverted format, and generally, the initial test data may be in a JSON or XML format.
In a specific example, the template is "@ name @ age @ enum (M, F)", data corresponding to the placeholder "@ name" is "lie si", data corresponding to the placeholder "@ age" is "76", data corresponding to the placeholder "@ age (M, F)" is "M", and the generated initial test data is "lie si 76M".
In some optional implementation manners of this embodiment, if there is no data generation rule corresponding to the placeholder, the placeholder is taken as data corresponding to the placeholder. For example, the template is "@ name @ age @ enum (M, F)", where the placeholder "@ age" has no corresponding data generation rule, and the finally obtained initial test data is "litquad.
Step 205, converting the data format of the initial test data into a target data format to obtain target test data.
In this embodiment, the execution subject may convert the data format of the initial test data into a target data format matched with the interface to be tested, so that the test data may be directly applied to the test task of the interface to be tested. For example, when the initial test data is in the JSON format and the target data acquired in step 201 is in the XML format, the execution body may deserialize the initial test data by using GSON to obtain the test data in the XML format.
According to the method and the device for generating the test data, the meta structure data are generated based on the parameter structure information of the interface to be tested, the template of the interface to be tested is determined based on the meta structure data, then the initial test data are automatically generated based on the template, and the data format of the initial test data is converted into the target data format matched with the interface to be tested. The test data with different formats can be automatically generated, and the efficiency of generating the test data is improved.
Referring next to FIG. 4, FIG. 4 is a flow diagram for one embodiment of generating dictionary words in a method for generating test data according to the present disclosure. In a preferred embodiment of the implementation shown in fig. 3, the execution subject may expand the dictionary repository through a process 400 shown in fig. 4, where the process 400 includes:
step 401, recognizing a construction rule of the dictionary word corresponding to the placeholder by using a pre-trained word generation model, and generating a new dictionary word based on the recognized construction rule of the dictionary word.
As an example, the execution subject may construct an initial RNN using an RNN (Recurrent Neural Network) as a word generation model. And then inputting dictionary words corresponding to the same placeholder as samples into the initial RNN, so that the initial RNN learns the construction rule of the dictionary words corresponding to the placeholder to obtain the trained RNN, and finally generating new dictionary words by the RNN. The execution subject may also use other machine learning models as the word generation model, which is not limited in this application.
Step 402, establishing a corresponding relationship between the new dictionary word and the placeholder.
And step 403, storing the new dictionary words into a dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
Through the process 400 shown in fig. 4, the execution subject may automatically extend the dictionary repository through the artificial intelligence model, so that the coverage of dictionary words in the dictionary repository may be improved.
As shown in fig. 5, the apparatus 500 for generating test data of the present embodiment includes: an information obtaining unit 501, configured to obtain parameter structure information and a target data format of an interface to be tested, where the parameter structure information includes entered-parameter structure information and entered-parameter structure information; a meta structure data generating unit 502 configured to generate meta structure data of the interface to be tested based on the parameter structure information, the meta structure data including data type information of the interface to be tested and reference relationship information that each type of data references other types of data; a template determination unit 503 configured to determine a template of the interface to be tested based on the meta structure data, the template including placeholders matching with the meta structure data; an initial data generating unit 504 configured to generate initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on the corresponding relation between the preset placeholder and the data generation rule; generating data corresponding to each placeholder based on the data generation rule corresponding to each placeholder; replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data; and a data format conversion unit 505 configured to convert the data format of the initial test data into a target data format, so as to obtain target test data.
In some embodiments, the apparatus further comprises a template generation unit configured to: determining a parameter recursion generation structure of each data type in the data type information of the meta-structure data based on the reference relation information of the meta-structure data, wherein the parameter recursion generation structure represents the structure of the data type; determining a placeholder matched with each data type in the data type information of the meta-structure data; and recursively generating a structure based on the parameters of the data types, and combining the placeholders matched with the data types in the data type information of the meta-structure data into a template.
In some embodiments, the template determination unit 503 is further configured to: retrieving a preset template database based on the meta-structure data; if a template corresponding to the meta-structure data exists in the template database, determining the template as a template of the interface to be tested; and if the template corresponding to the meta-structure data does not exist in the template database, executing a template generation step to generate a template of the interface to be tested.
In some embodiments, the meta structure data further includes a field name of the field type data and a value type and a value range of the base type data; and the template generation unit is further configured to: determining dictionary words matched with field names of the field type data and/or value types and value ranges of the basic type data from a preset dictionary library based on a preset matching strategy in response to the fact that the data type information of the meta structure data comprises the field type data and/or the basic type data; determining placeholders corresponding to dictionary words based on the corresponding relation between preset dictionary words and the placeholders; and determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
In some embodiments, the apparatus further comprises a dictionary repository expansion unit configured to: recognizing a construction rule of the dictionary words corresponding to the placeholders by adopting a pre-trained word generation model, and generating new dictionary words based on the recognized construction rule of the dictionary words; establishing a corresponding relation between the new dictionary words and the placeholders; and storing the new dictionary words into the dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
In some embodiments, the initial data generation unit 504 is further configured to: and if the data generation rule corresponding to the placeholder does not exist, taking the placeholder as the data corresponding to the placeholder.
Referring now to fig. 6, a schematic diagram of an electronic device (e.g., the server or terminal device of fig. 1) 600 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the use range of the embodiments of the present disclosure.
As shown in fig. 6, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 6 may represent one device or may represent multiple devices as desired.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. 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 via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of embodiments of the present disclosure. It should be noted that the computer readable medium described 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 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. In embodiments of the 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 embodiments of the present disclosure, however, a computer readable signal medium may comprise 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: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring parameter structure information and a target data format of an interface to be tested, wherein the parameter structure information comprises parameter entering structure information and parameter exiting structure information; generating meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data comprises data type information of the interface to be tested and reference relation information of each type of data for referencing other types of data; determining a template of the interface to be tested based on the meta-structure data, the template including placeholders that match the meta-structure data; generating initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on the corresponding relation between the preset placeholder and the data generation rule; generating data corresponding to each placeholder based on the data generation rule corresponding to each placeholder; replacing each placeholder in the template with data corresponding to each placeholder to obtain initial test data; and converting the data format of the initial test data into a target data format to obtain target test data.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, 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 computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
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 and/or flowchart illustration, and combinations of blocks in the block diagrams and/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. The described units may also be provided in a processor, and may be described as: a processor includes an information acquisition unit, a meta structure data generation unit, a template determination unit, an initial data generation unit, and a data format conversion unit. The names of these units do not in some cases form a limitation on the unit itself, and for example, the information acquiring unit may also be described as a "unit that acquires parameter structure information and target data format of the interface to be tested".
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention in the embodiments of the present disclosure is not limited to the specific combination of the above-mentioned features, but also encompasses other embodiments in which any combination of the above-mentioned features or their equivalents is made without departing from the inventive concept as defined above. For example, the above features and (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure are mutually replaced to form the technical solution.

Claims (14)

1. A method for generating test data, comprising:
acquiring parameter structure information and a target data format of an interface to be tested, wherein the parameter structure information comprises parameter entering structure information and parameter exiting structure information;
generating meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data comprises data type information of the interface to be tested and reference relation information of each type of data for referencing other types of data;
determining a template of the interface to be tested based on the meta-structure data, the template including placeholders that match the meta-structure data;
generating initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on a corresponding relation between a preset placeholder and the data generation rule; generating data corresponding to the placeholders based on data generation rules corresponding to the placeholders; replacing each placeholder in the template with data corresponding to each placeholder to obtain the initial test data;
and converting the data format of the initial test data into the target data format to obtain target test data.
2. The method of claim 1, wherein the template is obtained via the template generation step of:
determining a parameter recursion generation structure of each data type in the data type information of the meta-structure data based on the reference relation information of the meta-structure data, wherein the parameter recursion generation structure represents the structure of the data type;
determining a placeholder matched with each data type in the data type information of the meta-structure data;
and recursively generating a structure based on the parameters of the data types, and combining the placeholders matched with the data types in the data type information of the meta-structure data into a template.
3. The method of claim 2, wherein determining a template for the interface to be tested based on the meta structure data comprises:
retrieving a preset template database based on the meta-structure data;
if a template corresponding to the meta-structure data exists in the template database, determining the template as the template of the interface to be tested;
and if the template corresponding to the meta-structure data does not exist in the template database, executing the template generation step to generate the template of the interface to be tested.
4. The method of claim 2, wherein the meta structure data further comprises a field name of the field type data and a value type and a value range of the base type data; and the number of the first and second groups,
determining placeholders matched with the data types in the data type information of the meta-structure data, wherein the placeholders comprise:
in response to the fact that the data type information of the meta-structure data comprises field type data and/or basic type data, determining dictionary words matched with field names of the field type data and/or value types and value ranges of the basic type data from a preset dictionary library based on a preset matching strategy;
determining placeholders corresponding to dictionary words based on a preset corresponding relation between the dictionary words and the placeholders;
and determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
5. The method of claim 3, wherein the method further comprises:
recognizing a construction rule of the dictionary words corresponding to the placeholders by adopting a pre-trained word generation model, and generating new dictionary words based on the recognized construction rule of the dictionary words;
establishing a corresponding relation between the new dictionary words and the placeholders;
and storing the new dictionary words into the dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
6. The method of one of claims 1 to 5, wherein generating initial test data based on the template further comprises:
and if the data generation rule corresponding to the placeholder does not exist, determining the placeholder as the data corresponding to the placeholder.
7. An apparatus for generating test data, comprising:
the device comprises an information acquisition unit, a parameter configuration unit and a target data format, wherein the information acquisition unit is configured to acquire parameter configuration information and a target data format of an interface to be tested, and the parameter configuration information comprises parameter configuration information and parameter configuration information;
the meta-structure data generating unit is configured to generate meta-structure data of the interface to be tested based on the parameter structure information, wherein the meta-structure data comprises data type information of the interface to be tested and reference relation information of each type of data referring to other types of data;
a template determination unit configured to determine a template of the interface to be tested based on the meta structure data, the template including placeholders matching the meta structure data;
an initial data generation unit configured to generate initial test data based on the template, including: determining a data generation rule corresponding to each placeholder in the template based on a corresponding relation between a preset placeholder and the data generation rule; generating data corresponding to the placeholders based on data generation rules corresponding to the placeholders; replacing each placeholder in the template with data corresponding to each placeholder to obtain the initial test data;
and the data format conversion unit is configured to convert the data format of the initial test data into the target data format to obtain target test data.
8. The apparatus of claim 7, wherein the apparatus further comprises a template generation unit configured to:
determining a parameter recursion generation structure of each data type in the data type information of the meta-structure data based on the reference relation information of the meta-structure data, wherein the parameter recursion generation structure represents the structure of the data type;
determining a placeholder matched with each data type in the data type information of the meta-structure data;
and recursively generating a structure based on the parameters of the data types, and combining the placeholders matched with the data types in the data type information of the meta-structure data into a template.
9. The apparatus of claim 8, wherein the template determination unit is further configured to:
retrieving a preset template database based on the meta-structure data;
if a template corresponding to the meta-structure data exists in the template database, determining the template as the template of the interface to be tested;
and if the template corresponding to the meta-structure data does not exist in the template database, executing the template generation step to generate the template of the interface to be tested.
10. The apparatus of claim 8, wherein the meta structure data further comprises a field name of the field type data and a value type and a value range of the base type data;
and the template generation unit is further configured to:
in response to the fact that the data type information of the meta-structure data comprises field type data and/or basic type data, determining dictionary words matched with field names of the field type data and/or value types and value ranges of the basic type data from a preset dictionary library based on a preset matching strategy;
determining placeholders corresponding to dictionary words based on a preset corresponding relation between the dictionary words and the placeholders;
and determining the placeholder corresponding to the dictionary word as the placeholder matched with the field type data or the basic type data matched with the dictionary word.
11. The apparatus of claim 9, wherein the apparatus further comprises a dictionary repository expansion unit configured to:
recognizing a construction rule of the dictionary words corresponding to the placeholders by adopting a pre-trained word generation model, and generating new dictionary words based on the recognized construction rule of the dictionary words;
establishing a corresponding relation between the new dictionary words and the placeholders;
and storing the new dictionary words into the dictionary library based on the corresponding relation between the new dictionary words and the placeholders.
12. The apparatus according to one of claims 7 to 11, wherein the initial data generation unit is further configured to:
and if the data generation rule corresponding to the placeholder does not exist, taking the placeholder as the data corresponding to the placeholder.
13. An electronic device, comprising:
one or more processors;
a storage device having one or more programs stored thereon,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method of any one of claims 1-6.
CN202011371263.5A 2020-11-30 2020-11-30 Method and apparatus for generating test data Pending CN113778846A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011371263.5A CN113778846A (en) 2020-11-30 2020-11-30 Method and apparatus for generating test data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011371263.5A CN113778846A (en) 2020-11-30 2020-11-30 Method and apparatus for generating test data

Publications (1)

Publication Number Publication Date
CN113778846A true CN113778846A (en) 2021-12-10

Family

ID=78835243

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011371263.5A Pending CN113778846A (en) 2020-11-30 2020-11-30 Method and apparatus for generating test data

Country Status (1)

Country Link
CN (1) CN113778846A (en)

Similar Documents

Publication Publication Date Title
CN103678454A (en) Method and system for user-specific synthetic context object matching
CN103678455A (en) Method and system for generation of synthetic context objects
KR102342604B1 (en) Method and apparatus for generating neural network
US20170011077A1 (en) Scalable annotation architecture
CN111159220A (en) Method and apparatus for outputting structured query statement
US20210109747A1 (en) Auto mapping recommender
KR20210037619A (en) Multimodal content processing method, apparatus, device and storage medium
CN111813846B (en) Data analysis processing system and data processing method
US20180137098A1 (en) Methods and systems for providing universal portability in machine learning
CN113778846A (en) Method and apparatus for generating test data
CN112489652A (en) Text acquisition method and device for voice information and storage medium
CN111008213A (en) Method and apparatus for generating language conversion model
CN110929209A (en) Method and device for sending information
CN112182255A (en) Method and apparatus for storing media files and for retrieving media files
CN111354345A (en) Method, apparatus, device and medium for generating speech model and speech recognition
CN113468344B (en) Entity relationship extraction method and device, electronic equipment and computer readable medium
CN111221424B (en) Method, apparatus, electronic device, and computer-readable medium for generating information
CN111125154B (en) Method and apparatus for outputting structured query statement
CN111562864B (en) Picture display method, electronic device and computer readable medium
CN110457325B (en) Method and apparatus for outputting information
CN112200173B (en) Multi-network model training method, image labeling method and face image recognition method
CN112446192A (en) Method, device, electronic equipment and medium for generating text labeling model
CN112417151A (en) Method for generating classification model and method and device for classifying text relation
CN109858045A (en) Machine translation method and device
CN111753080A (en) Method and apparatus for outputting information

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