CN112100049A - Method, device, medium and equipment for generating test data - Google Patents

Method, device, medium and equipment for generating test data Download PDF

Info

Publication number
CN112100049A
CN112100049A CN201910528693.4A CN201910528693A CN112100049A CN 112100049 A CN112100049 A CN 112100049A CN 201910528693 A CN201910528693 A CN 201910528693A CN 112100049 A CN112100049 A CN 112100049A
Authority
CN
China
Prior art keywords
data
data entity
member variables
entity class
class
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
CN201910528693.4A
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 Shuju Xinyun Information Technology Co ltd
Original Assignee
Beijing Shuju Xinyun 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 Shuju Xinyun Information Technology Co ltd filed Critical Beijing Shuju Xinyun Information Technology Co ltd
Priority to CN201910528693.4A priority Critical patent/CN112100049A/en
Publication of CN112100049A publication Critical patent/CN112100049A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/288Entity relationship models
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a method, a device, a medium and equipment for generating functional test data, wherein the method comprises the following steps: traversing the data entity class in the specified directory, and initializing and assigning values to the data entity class; and taking the data entity class subjected to the initialization assignment as test data. By the method, required test data can be automatically generated, time and labor are saved, time and energy of test/development personnel are greatly saved, and the test/development personnel can be copied, distributed and reused.

Description

Method, device, medium and equipment for generating test data
Technical Field
The present application relates to the field of network security, and in particular, to a method, an apparatus, and a medium for generating test data.
Background
In the testing stage (unit testing, interface debugging) of system development, under the condition that the front-end page is not provided, the testing/developing personnel is often required to construct the testing data by themselves, when the quantity of the testing data objects required in the testing scene is large, the testing data is constructed and the time is consumed, the process is very dull, and the testing efficiency of the testing/developing personnel is extremely easy to be influenced.
Disclosure of Invention
In order to solve the above-described problems, the present invention provides a method of generating test data, comprising:
traversing the data entity class in the specified directory, and initializing and assigning values to the data entity class;
and taking the data entity class subjected to the initialization assignment as test data.
The data entity class comprises member variables, and the types of the member variables comprise native data types and/or custom data types;
traversing the data entity class in the specified directory, and initializing assignment to the data entity class comprises:
traversing the data entity class in the specified directory, if all the member variables of the data entity class are the member variables of the primary data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class in a query table;
if the data entity class comprises member variables of the custom data type and member variables of the native data type, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
Traversing the data entity class in the specified directory, and before initializing and assigning values to the data entity class, further comprising:
judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
traversing the data entity class in the specified directory, and initializing and assigning the data entity class specifically comprises:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
The lookup table comprises a simple lookup table and a complex lookup table;
traversing the data entity class in the specified directory, and initializing and assigning the data entity class specifically comprises:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the simple inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
The lookup table is a hash table.
The member variables in the data entity class are defined as follows:
all the types of the member variables in the data entity class are native data types; or
The types of all member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types; or
All the member variables in the data entity class are of custom data types, wherein the member variables of the custom data types comprise member variables of which the types are native data types and/or member variables of other custom data types.
The invention provides a device for generating test data, comprising:
the traversal assignment module is used for traversing the data entity class in the specified directory and initializing assignment to the data entity class;
and the determining module is used for taking the data entity class subjected to the initialized assignment as test data.
The data entity class comprises member variables, and the types of the member variables comprise native data types and/or custom data types;
the traversal assignment module is configured to: traversing the data entity class in the specified directory, if all the member variables of the data entity class are the member variables of the primary data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class in a query table;
if the data entity class comprises member variables of the custom data type and member variables of the native data type, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
The means for generating test data further comprises:
the judging module is used for judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
the traversal assignment module is configured to:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
The lookup table comprises a simple lookup table and a complex lookup table;
the traversal assignment module is configured to:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the simple inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
The lookup table is a hash table.
The member variables in the data entity class are defined as follows:
all the types of the member variables in the data entity class are native data types; or
The types of all member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types;
all the member variables in the data entity class are of custom data types, wherein the member variables of the custom data types comprise member variables of which the types are native data types and/or member variables of other custom data types.
The present invention provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, carries out the steps of a method of generating test data.
The invention provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of generating test data when executing the program.
The method and the device can automatically generate the required test data, save time and labor, greatly save the time and energy of test/development personnel, and can be copied, distributed and reused.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the application and together with the description, serve to explain the principles of the application. In the drawings, like reference numerals are used to indicate like elements. The drawings in the following description are directed to some, but not all embodiments of the application. For a person skilled in the art, other figures can be derived from these figures without inventive effort.
FIG. 1 is a flow diagram illustrating a method of generating test data in accordance with an exemplary embodiment;
FIG. 2 is a block diagram illustrating an apparatus for generating test data in accordance with an exemplary embodiment;
FIG. 3 is a block diagram illustrating an apparatus for generating test data according to an example embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
As shown in fig. 1, a method of generating test data, comprising:
step S101, traversing the data entity class in the specified directory, and initializing and assigning values to the data entity class;
and step S102, taking the data entity class subjected to the initialization assignment as test data.
The data entity class comprises member variables, and the types of the member variables comprise native data types and/or custom data types;
wherein, the member variables of the data entity class can be defined according to the following modes:
all the types of the member variables in the data entity class are native data types; or
The types of the member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types; or
All the member variables in the data entity class are of the custom data type, wherein the member variables of the custom data type comprise member variables of which the types are native data types and/or member variables of other custom data types.
The member variables of the native data type may be member variables of a primitive data type in the program language, such as member variables of a numeric type, member variables of a character type, and member variables of a boolean type. The member variables of the native data type may be directly initialized and assigned values.
The member variables of the custom data type are the member variables of the data type defined according to the requirement. The member variables of the custom data type may correspond to a class of data entities that includes member variables of types that may be native data types and/or custom data types.
Therefore, in the process of traversing the data entity class and initializing and assigning the data entity class, the data entity class containing the user-defined member variable can be initialized and assigned only by traversing the data entity class containing the user-defined member variable for multiple times.
Step S101 further includes:
traversing the data entity classes in the specified directory; if all the member variables of the data entity class are the member variables of the primary data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class into a query table;
if the data entity class comprises member variables of the custom data type and member variables of the native data type, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
Wherein the look-up table may be a hash table. And the hash table is used, so that the query speed is further increased.
The present application will be described in detail below with reference to examples.
Example one
Under a given directory, there are 3 data entity classes:
Figure BDA0002099029870000081
the data entity class Public class Admin comprises a member variable User, wherein the member variable User is a custom data type and corresponds to a data entity class Public class User, the data entity class Public class User comprises three member variables, wherein name and age are native data types, name is a character type, age is an integer type, and count is a custom type and corresponds to a data entity class Public count, the data entity class Public class count comprises a member variable count, and count is a native data type and is a character type.
In the present application, to generate test data:
and traversing the data entity class under the specified directory, wherein the member variables contained in the data entity class Public class Admin are self-defined types, and the query table is empty at the moment and cannot be initialized and assigned, so that the next data entity class is continuously traversed, the data entity class Public class User comprises three member variables, wherein the name and the age are native data types and can be initialized and assigned, but the count is a self-defined type, and the query table is empty at the moment and cannot be initialized and assigned, so that the data entity class Public class User continuously traverses the next data entity class after initializing and assigning the name and the age, and the member variable countynname contained in the data entity class Public class is a native data type and can be initialized and assigned.
In the traversal process, only all member variables of the data entity class Publicclass count are initialized and assigned, that is, only the data entity class Publicclass count is initialized and assigned, so that the data entity class Publicclass count and corresponding values thereof are stored in the lookup table.
In order to assign values to all the data entity classes under the specified directory, traversing the data entity classes under the directory again; the method comprises the steps of assigning no value to a data entity class Public class Admin, assigning no value to a member variable user of the data entity class Public class Admin, inquiring a query table, wherein the query table only has a value corresponding to the data entity class Public class count and has no value of the member variable user, so that the data entity class Public class Admin cannot be initialized and assigned. Therefore, the next data entity class is continuously traversed, the data entity class Public class User comprises three member variables, wherein the member variables name and age are already assigned, only the member variable count is not assigned, a query table is queried, the value of Public class count is stored in the query table, and therefore the value of Public class count is assigned to the member variable count in the data entity class Public class User. So far, the three member variables of the data entity class Public class User are all assigned, and the data entity class Public class User and corresponding values are stored in a lookup table. And continuously traversing the next data entity class, wherein the data entity class Public class Country is assigned, and the traversal is ended.
In the traversal process, the data entity class Public class User is initialized and assigned, and the data entity class Public class Admin is not initialized and assigned.
In order to assign values to all the data entity classes under the specified directory, traversing the data entity classes under the directory again; the method comprises the steps that a data entity class Public class Admin is not assigned, a member variable User is not assigned, a query table is queried, the query table has a value of the data entity class Public class User, the value of the data entity class Public class User is assigned to the member variable User of the data entity class Public class Admin, and then the data entity class Public class Admin is assigned, and the data entity class Public class Admin and a corresponding value are stored in the query table. And continuously traversing the next data entity class, wherein the Public class User is assigned, continuously traversing, the Public class Country is assigned, and finishing the traversing.
After the traversal, all the data entity classes under the specified directory are assigned successfully. And taking the assigned data entity class as test data. The class of data entities may be selected for testing as desired.
Further, in order to increase the speed of traversal, before step S101, the method further includes:
step S100, judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
step S101 specifically includes:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
The present application will be described in detail below with reference to examples.
Example two
Under a given directory, there are 3 data entity classes:
Figure BDA0002099029870000111
the data entity class Public class Admin comprises a member variable User, wherein the member variable User is a custom data type and corresponds to a data entity class Public class User, the data entity class Public class User comprises three member variables, wherein name and age are native data types, name is a character type, age is an integer type, and count is a custom type and corresponds to a data entity class Public count, the data entity class Public class count comprises a member variable count, and count is a native data type and is a character type.
In the present application, to generate test data:
the data entity class under the appointed directory is classified firstly, namely, whether the data entity class under the appointed directory is a simple data entity class or a complex data entity class is judged. The member variables contained in the data entity class Public class Admin are of custom data types, so that the data entity class is not a simple data entity class and is put into a complex data entity class array. The data entity class Public class User comprises a custom member variable count, so that the data entity class is not a simple data entity class and is put into a complex data entity class array. The member variable contained in the Public class Country of the data entity class is a native data type, belongs to the simple data entity class, and is put into the simple data entity class array.
Traversing the data entity class in the simple data entity class array, in this embodiment, the simple data entity class array includes a data entity class Public class count, and initializing and assigning a member variable countryname of a native data type of the data entity class Public class count. And storing the initialized and assigned data entity class Public class Country and corresponding values into a lookup table.
And traversing the data entity class in the complex data entity class array after the simple data entity class array is traversed. The method comprises the steps of querying a query table, wherein a member variable User contained in a data entity class Public class Admin does not have a value related to the User in the query table, and cannot be initialized and assigned, so that the next data entity class is continuously traversed, the data entity class Public class User comprises three member variables, wherein name and age are native data types and can be initialized and assigned, count is a User-defined type, the query table is queried, and the value of Public class count is stored in the query table, so that the value of the Public class count is assigned to the member variable count in the data entity class Public class User. All three member variables of the data entity class Public class User are assigned, and the data entity class Public class User and corresponding values are stored in a lookup table. This traversal is ended.
In the traversal process, the data entity class Public class User is initialized and assigned, and the data entity class Public class Admin is not initialized and assigned.
In order to assign values to all data entity classes in the specified directory, traversing the data entity classes in the complex data entity class array in the directory again; the method comprises the steps of assigning no value to a data entity class Public class Admin, assigning no value to a member variable User of the data entity class User, inquiring a query table, assigning the value of the data entity class Public class User to the member variable User of the data entity class Public class Admin, assigning the value of the data entity class Public class Admin, and storing the data entity class Public class Admin and the corresponding value into the query table. And continuously traversing the next data entity class, assigning a value to the Public class User, and ending the traversal.
After the traversal, all the data entity classes under the specified directory are assigned successfully. And taking the assigned data entity class as test data. The class of data entities may be selected for testing as desired.
By dividing the data entity class into the simple data entity class and the complex data entity class, after the simple data entity class is traversed for the first time, the simple data entity class does not need to be traversed again in the subsequent traversal process, and the traversal speed is improved only in the complex data entity class.
Further, in order to improve the query speed, the query table is divided into a simple query table and a complex query table;
step S101 specifically includes:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in a simple inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
The present application will be described in detail below with reference to examples.
EXAMPLE III
Under a given directory, there are 3 data entity classes:
Figure BDA0002099029870000131
the data entity class Public class Admin comprises a member variable User, wherein the member variable User is a custom data type and corresponds to a data entity class Public class User, the data entity class Public class User comprises three member variables, wherein name and age are native data types, name is a character type, age is an integer type, and count is a custom type and corresponds to a data entity class Public count, the data entity class Public class count comprises a member variable count, and count is a native data type and is a character type.
In the present application, to generate test data:
the data entity class under the appointed directory is classified firstly, namely, whether the data entity class under the appointed directory is a simple data entity class or a complex data entity class is judged. The member variables contained in the data entity class Public class Admin are of custom data types, so that the data entity class is not a simple data entity class and is put into a complex data entity class array. The data entity class Public class User comprises a custom member variable count, so that the data entity class is not a simple data entity class and is put into a complex data entity class array. The member variable contained in the Public class Country of the data entity class is a native data type, belongs to the simple data entity class, and is put into the simple data entity class array.
Traversing the data entity class in the simple data entity class array, in this embodiment, the simple data entity class array includes a data entity class Public class count, and initializing and assigning a member variable countryname of a native data type of the data entity class Public class count. And storing the initialized and assigned data entity class Public class Country and corresponding values into a simple lookup table.
And traversing the data entity class in the complex data entity class array after the simple data entity class array is traversed. The method comprises the steps of querying a simple query table by a member variable User contained in a data entity class Public class Admin, wherein the simple query table does not have a value related to the User and cannot be initialized and assigned, so that the next data entity class is continuously traversed, the data entity class Public class User comprises three member variables, wherein name and age are native data types and can be initialized and assigned, count is a User-defined type, the simple query table is queried, the value of Public class count is stored in the simple query table, and the value of the Public class count is assigned to the member variable count in the data entity class Public class User. All three member variables of the data entity class Public class User are assigned, and the data entity class Public class User and corresponding values are stored in a complex query table. This traversal is ended.
In the traversal process, the data entity class Public class User is initialized and assigned, and the data entity class Public class Admin is not initialized and assigned.
In order to assign values to all data entity classes in the specified directory, traversing the data entity classes in the complex data entity class array in the directory again; the method comprises the steps of assigning no value to a data entity class Public class Admin and assigning no value to a member variable User of the data entity class Public class Admin, inquiring a complex query table, wherein the complex query table has a value of the data entity class Public class User, assigning the value of the data entity class Public class User to the member variable User of the data entity class Public class Admin, assigning the value of the data entity class Public class Admin, and storing the data entity class Public class Admin and a corresponding value into the complex query table. And continuously traversing the next data entity class, assigning a value to the Public class User, and ending the traversal.
After the traversal, all the data entity classes under the specified directory are assigned successfully. And taking the assigned data entity class as test data. The class of data entities may be selected for testing as desired.
The evaluation result of the simple data entity class is put into the simple query table, the evaluation result of the complex data entity class is put into the complex query table, and when the member variable value is queried for the data entity class which is not evaluated in the complex data entity class array, the member variable value only needs to be queried in the complex query table, so that the query speed is increased.
Through the embodiment, the scheme is based on the principles of traversing and analyzing the data entity classes, the data types of all member variables in the data entity classes are automatically detected, the mutual dependency relationship among the member variables is found, the most basic data entity class is generated firstly, the dependent data entity class is generated, and finally the generated result is output as the test data, so that the burden of a test/development worker is greatly reduced.
The present application also provides an apparatus for generating test data, as shown in fig. 2, the apparatus for generating test data shown in fig. 2 includes:
the traversal assignment module is used for traversing the data entity class in the specified directory and initializing assignment to the data entity class;
and the determining module is used for taking the data entity class subjected to the initialized assignment as test data.
The data entity class comprises member variables, and the types of the member variables comprise native data types and/or custom data types;
the traversal assignment module is used for traversing the data entity class in the specified directory, if all the member variables of the data entity class are the member variables of the native data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class into a query table;
if the data entity class comprises member variables of the custom data type, and if the data entity class comprises the member variables of the type of the native data type, performing initialization assignment on the member variables of the type of the native data type; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in a lookup table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring a lookup table whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values;
wherein the look-up table may be a hash table.
The member variables in a data entity class are defined as follows:
all the types of the member variables in the data entity class are native data types; or
The types of all member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types;
all the member variables in the data entity class are of the custom data type, wherein the member variables of the custom data type comprise member variables of which the types are native data types and/or member variables of other custom data types.
The present application also provides an apparatus for generating test data, as shown in fig. 3, the apparatus for generating test data shown in fig. 3 includes:
the judging module is used for judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
the traversal assignment module is used for:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in a query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in a lookup table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring a query table whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
In the apparatus for producing test data provided herein, the look-up table may further include a simple look-up table and a complex look-up table. The traversal assignment module is used for: traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in a simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in a simple inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into a complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
The present application also provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method as set forth in the present application.
The present application further provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method proposed by the present application when executing the program.
The above-described aspects may be implemented individually or in various combinations, and such variations are within the scope of the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus (device), or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media having computer-usable program code embodied in the medium. Computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, including, but not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by the computer, and the like. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art.
The present invention has been described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (devices) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that an article or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of additional like elements in the article or device comprising the element.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, it is intended that the present invention cover the modifications and variations of this invention provided they come within the scope of the appended claims and their equivalents.

Claims (14)

1. A method of generating test data, comprising:
step 101) traversing data entity classes in a specified directory, and initializing and assigning values to the data entity classes;
step 102) taking the data entity class after the initialization assignment as test data.
2. The method of generating test data according to claim 1, wherein the class of data entities includes member variables, the types of the member variables including native data types and/or custom data types;
the step 101) comprises:
traversing the data entity class in the specified directory, if all the member variables of the data entity class are the member variables of the primary data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class in a query table;
if the data entity class comprises member variables of the custom data type and member variables of the native data type, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
3. The method of generating test data according to claim 2, prior to step 101), further comprising:
step 100) judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
step 101) specifically comprises:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
4. The method of generating test data of claim 3, wherein the look-up tables comprise a simple look-up table and a complex look-up table;
step 101) specifically comprises:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the simple inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
5. The method of generating test data according to any one of claims 1-4, wherein the look-up table is a hash table.
6. The method of generating test data according to any one of claims 1 to 4, wherein the member variables in the class of data entities are defined in the following manner:
all the types of the member variables in the data entity class are native data types; or
The types of all member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types; or
All the member variables in the data entity class are of custom data types, wherein the member variables of the custom data types comprise member variables of which the types are native data types and/or member variables of other custom data types.
7. An apparatus for generating test data, comprising:
the traversal assignment module is used for traversing the data entity class in the specified directory and initializing assignment to the data entity class;
and the determining module is used for taking the data entity class subjected to the initialized assignment as test data.
8. The apparatus of generating test data according to claim 7, wherein the class of data entities includes member variables, types of the member variables including native data types and/or custom data types;
the traversal assignment module is configured to: traversing the data entity class in the specified directory, if all the member variables of the data entity class are the member variables of the primary data type, performing initialization assignment on all the member variables of the data entity class, and storing the data entity class in a query table;
if the data entity class comprises member variables of the custom data type and member variables of the native data type, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable of the custom data type exists in the inquiry table; if yes, assigning a value to the member variable of which the type is the custom data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing the data entity class in the specified directory, determining unassigned member variables in the data entity class for the unassigned data entity class, inquiring whether the lookup table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
9. The apparatus for generating test data of claim 7, wherein the apparatus further comprises:
the judging module is used for judging whether the data entity class is a simple data entity class; if yes, putting a simple data entity class array; if not, putting a complex entity data array; the simple data entity class is a member variable, and the types of the member variables are all native data types;
the traversal assignment module is configured to:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the query table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, and inquiring whether the query table has values corresponding to the unassigned member variables; if so, assigning the unassigned member variable, judging whether all the member variables of the data entity class are assigned, and if so, storing the data entity class into the query table; until all data entity classes have been assigned values.
10. The apparatus for generating test data of claim 9, wherein the look-up tables comprise a simple look-up table and a complex look-up table;
the traversal assignment module is configured to:
traversing the data entity class in the simple data entity class array; assigning the member variables in the data entity class and storing the member variables in the simple lookup table;
traversing data entity classes in the complex entity data class array; if the data entity class comprises member variables of which the types are the native data types, carrying out initialization assignment on the member variables of which the types are the native data types; for the member variable with the type as the custom data type, inquiring whether a value corresponding to the member variable with the type as the custom data type exists in the simple inquiry table; if yes, the type is assigned for the member variable of the user-defined data type; judging whether all member variables in the data entity class are assigned, if so, storing the data entity class into the complex query table;
traversing data entity classes in the complex entity data class array, determining unassigned member variables in the data entity classes for the unassigned data entity classes, inquiring whether the complex query table has values corresponding to the unassigned member variables, and if so, assigning the unassigned member variables; judging whether all member variables of the data entity class are assigned, if so, storing the data entity class into the complex query table; until all data entity classes have been assigned values.
11. Apparatus for generating test data according to any one of claims 7 to 10, in which the look-up table is a hash table.
12. Apparatus for generating test data according to any one of claims 7 to 10, wherein the member variables in the class of data entities are defined in the following manner:
all the types of the member variables in the data entity class are native data types; or
The types of all member variables in the data entity class comprise a native data type and a custom data type, wherein the member variables of the custom data type comprise member variables of which the types are the native data type and/or member variables of other custom data types;
all the member variables in the data entity class are of custom data types, wherein the member variables of the custom data types comprise member variables of which the types are native data types and/or member variables of other custom data types.
13. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 5.
14. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of any one of claims 1 to 5 when executing the program.
CN201910528693.4A 2019-06-18 2019-06-18 Method, device, medium and equipment for generating test data Pending CN112100049A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910528693.4A CN112100049A (en) 2019-06-18 2019-06-18 Method, device, medium and equipment for generating test data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910528693.4A CN112100049A (en) 2019-06-18 2019-06-18 Method, device, medium and equipment for generating test data

Publications (1)

Publication Number Publication Date
CN112100049A true CN112100049A (en) 2020-12-18

Family

ID=73748681

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910528693.4A Pending CN112100049A (en) 2019-06-18 2019-06-18 Method, device, medium and equipment for generating test data

Country Status (1)

Country Link
CN (1) CN112100049A (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100803581B1 (en) * 2000-10-26 2008-02-15 삼성전자주식회사 Apparatus for automatic generating test data and method thereof
CN103268285A (en) * 2013-05-31 2013-08-28 百度在线网络技术(北京)有限公司 Method and device for automatic generation of robustness test case of API interface
CN104714881A (en) * 2013-12-15 2015-06-17 广州凯乐软件技术有限公司 Table-driven unit test system and method
CN104731587A (en) * 2015-03-12 2015-06-24 用友网络科技股份有限公司 Unit testing data generating method and unit testing data generating system
CN105828196A (en) * 2016-03-09 2016-08-03 青岛海信电器股份有限公司 Intelligent television data processing method and device
CN105912470A (en) * 2016-04-11 2016-08-31 苏州简约纳电子有限公司 Test case generation method suitable for ASN.1
CN108549531A (en) * 2018-04-19 2018-09-18 携程旅游网络技术(上海)有限公司 Complex type data automatic generation method, device, electronic equipment, storage medium
CN109299003A (en) * 2018-08-31 2019-02-01 苏州洞察云信息技术有限公司 A kind of full-automatic testing case driving generation system towards complex software

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100803581B1 (en) * 2000-10-26 2008-02-15 삼성전자주식회사 Apparatus for automatic generating test data and method thereof
CN103268285A (en) * 2013-05-31 2013-08-28 百度在线网络技术(北京)有限公司 Method and device for automatic generation of robustness test case of API interface
CN104714881A (en) * 2013-12-15 2015-06-17 广州凯乐软件技术有限公司 Table-driven unit test system and method
CN104731587A (en) * 2015-03-12 2015-06-24 用友网络科技股份有限公司 Unit testing data generating method and unit testing data generating system
CN105828196A (en) * 2016-03-09 2016-08-03 青岛海信电器股份有限公司 Intelligent television data processing method and device
CN105912470A (en) * 2016-04-11 2016-08-31 苏州简约纳电子有限公司 Test case generation method suitable for ASN.1
CN108549531A (en) * 2018-04-19 2018-09-18 携程旅游网络技术(上海)有限公司 Complex type data automatic generation method, device, electronic equipment, storage medium
CN109299003A (en) * 2018-08-31 2019-02-01 苏州洞察云信息技术有限公司 A kind of full-automatic testing case driving generation system towards complex software

Similar Documents

Publication Publication Date Title
CN109634682B (en) Configuration file updating method and device for application program
CN113792159A (en) Knowledge graph data fusion method and system
CN112905624B (en) Database extension method and device of low-code development platform
CN106843820B (en) Code processing method and device
CN110704418A (en) Block chain information query method, device and equipment
CN112947934A (en) Method, device and medium for dynamically transforming business logic
CN111984666B (en) Database access method, apparatus, computer readable storage medium and computer device
CN113010169A (en) Method and apparatus for converting UI diagram into code file
CN105187399A (en) Resource processing method and device
CN112100049A (en) Method, device, medium and equipment for generating test data
CN111078319B (en) Configuration data management method, device, storage medium and computer readable medium
CN111124382A (en) Attribute assignment method and device in Java and server
CN111177093A (en) Method, device and medium for sharing scientific and technological resources
CN114281461A (en) Management method, equipment and medium for configurable data source attributes
CN111736895A (en) Method, equipment and storage medium for merging and upgrading version numbers of software products
CN111090825A (en) Dynamic customization method for webpage content
CN112749159A (en) Form generation method and device, electronic equipment and storage medium
CN111125165A (en) Set merging method, device, processor and machine-readable storage medium
CN106775629B (en) Search file generation method and device
CN113792247B (en) Method, apparatus, device and medium for generating functional flow chart based on code characteristics
CN106951427B (en) Data extraction method and device for business object
CN112016580A (en) Application program name identification method and device and terminal
CN110968742A (en) Data filtering method and device
CN111338639B (en) Implementation method of instruction set of intelligent contract virtual machine of block chain
CN110968599B (en) Inquiry method and device based on Impala

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