Disclosure of Invention
The embodiment of the invention aims to provide a test data generation method and a test data generation device, so that the automation of test data generation is realized, and the time cost of testing is reduced. The specific technical scheme is as follows:
the embodiment of the invention provides a test data generation method, which comprises the following steps:
providing a type selection option;
receiving type information for the type selection option;
determining characteristic information corresponding to the type information and determining the quantity of test data to be generated;
and generating the number of test data meeting the characteristic information.
Optionally, the generating the number of test data satisfying the characteristic information includes:
providing a page including the property information;
receiving characteristic data which is input by a user on the page and meets the characteristic information;
and generating the test data meeting the characteristic data in quantity according to the characteristic data and the quantity of the test data to be generated.
Optionally, the determining the number of the test data to be generated includes:
providing a quantity input option;
and receiving the quantity of the test data to be generated, which is input by the user through the quantity input option.
Optionally, the type information includes at least one of the following information: mobile phone number, name of person, name of enterprise, organization code, unified social credit code of enterprise, and registration number of enterprise.
Optionally, when the type information includes a mobile phone number, the feature information includes a number segment, a region code, and a user number field;
when the type information comprises an organization code, the characteristic information comprises an enterprise body code and a check code;
when the type information comprises an enterprise unified social credit code, the characteristic information comprises: registering a management department code, an organization type code, an administrative region code of a registration management authority, an organization code and a check code;
when the type information comprises an enterprise registration number, the characteristic information comprises an administrative code, an enterprise category code, a sequence number and a check code.
Optionally, after the generating the number of test data satisfying the characteristic information, the method further includes:
encrypting the test data in a preset encryption mode;
and importing the encrypted test data into the hbase database.
An embodiment of the present invention further provides a test data generating apparatus, including:
a providing module for providing a type selection option;
a receiving module for receiving type information for the type selection option;
the determining module is used for determining the characteristic information corresponding to the type information and determining the quantity of the test data to be generated;
and the generating module is used for generating the test data of which the number meets the characteristic information.
Optionally, the generating module is specifically configured to provide a page including the characteristic information; receiving characteristic data which is input by a user on the page and meets the characteristic information; and generating the test data meeting the characteristic data in quantity according to the characteristic data and the quantity of the test data to be generated.
Optionally, the determining module is specifically configured to provide a quantity input option; and receiving the quantity of the test data to be generated, which is input by the user through the quantity input option.
Optionally, the type information includes at least one of the following information: mobile phone number, name of person, name of enterprise, organization code, unified social credit code of enterprise, and registration number of enterprise.
Optionally, when the type information includes a mobile phone number, the feature information includes a number segment, a region code, and a user number field;
when the type information comprises an organization code, the characteristic information comprises an enterprise body code and a check code;
when the type information comprises an enterprise unified social credit code, the characteristic information comprises: registering a management department code, an organization type code, an administrative region code of a registration management authority, an organization code and a check code;
when the type information comprises an enterprise registration number, the characteristic information comprises an administrative code, an enterprise category code, a sequence number and a check code.
Optionally, the apparatus further comprises:
the encryption module is used for encrypting the test data in a preset encryption mode after the test data with the quantity meeting the characteristic information is generated;
and the importing module is used for importing the encrypted test data into the hbase database.
The embodiment of the invention has the following beneficial effects:
the test data generation method and the test data generation device provided by the embodiment of the invention can provide type selection options for a user to select, so that type information aiming at the type selection options can be received; and further determining characteristic information corresponding to the type information, determining the number of test data to be generated, and generating the test data of which the number of the test data to be generated meets the characteristic information. Therefore, automation of generating test data can be realized, and the time cost of testing is reduced.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived from the embodiments given herein by one of ordinary skill in the art, are within the scope of the invention.
When the registration service is tested, after the personal information is registered, the registration can be returned, and only the registration can be deleted from the database or a new piece of data can be input; in the prior art, in order to increase the pressure resistance of a server, means such as caching are generally used, and thus, when the same data is used for testing, the testing requirements cannot be met due to various reasons such as caching. Many different pieces of data are used for testing, but it takes a relatively long time to simulate the data. Most people in the existing solution can only manually and incrementally modify personal information or clear cache, database data and the like, or collect personal information of colleagues for testing, so that the testing cost and time are greatly increased.
In order to avoid that the time consumed by manually inputting the test data one by one is too long and the time cost of the test is reduced, the embodiment of the invention provides a test data generation method, and the test data generation method of the embodiment of the invention is described in detail below.
An execution subject of the test data generation method provided by the embodiment of the present invention may be an electronic device, and specifically, the electronic device may be a server, a terminal, and the like.
The embodiment of the invention provides a test data generation method, which comprises the following steps:
providing a type selection option;
receiving type information for a type selection option;
determining characteristic information corresponding to the type information and determining the quantity of test data to be generated;
the number of test data satisfying the characteristic information is generated.
In the embodiment of the invention, a type selection option can be provided for a user to select, so that type information aiming at the type selection option can be received; and further determining characteristic information corresponding to the type information, determining the number of test data to be generated, and generating the test data of which the number of the test data to be generated meets the characteristic information. Therefore, automation of generating test data can be realized, and the time cost of testing is reduced.
Fig. 1 is a flowchart of a test data generation method according to an embodiment of the present invention. Referring to fig. 1, a method for generating test data according to an embodiment of the present invention may include:
s101, providing a type selection option.
Specifically, a trigger button may be provided first, and when it is detected that the trigger button is triggered, a type selection option may be provided for the user to select.
S102, receiving type information aiming at the type selection option.
The type information may include at least one of the following information: mobile phone number, name of person, name of enterprise, organization code, unified social credit code of enterprise, and registration number of enterprise.
Different type selection options correspond to different types of information, and a user can click one or more type selection options, so that the type information aiming at the type selection options can be received.
S103, determining characteristic information corresponding to the type information and determining the number of test data to be generated.
When the type information comprises a mobile phone number, the characteristic information comprises a number section, a region code and a user number field. As shown in fig. 2A, the sequence includes a 3-bit number segment, a 4-bit area code, and a 4-bit subscriber number.
When the type information comprises an organization code, the characteristic information comprises an enterprise body code and a check code. As shown in fig. 2B, the enterprise ontology code includes 8 bits of enterprise ontology code and 1 bit of check code in sequence.
When the type information comprises an enterprise unified social credit code, the characteristic information comprises: a registration authority code, an organization category code, a registration authority administrative area code, an organization code, and a check code. As shown in fig. 2C, the management department code of 1 bit, the organization type code of 1 bit, the registration authority administrative area code of 6 bits, the organization code of 9 bits, and the check code of 1 bit are included in this order.
When the type information includes an enterprise registration number, the characteristic information includes an administrative code, an enterprise category code, a sequence number and a check code. As shown in fig. 2D, the administrative code of 6 bits, the enterprise category code of 1 bit, the sequence number of 7 bits, and the check code of 1 bit are included in order.
When the type information includes a person's first name, the property information may include the number of words of the first or last name, such as 1 word, a compound name of 2 words, and so on.
Different types of information correspond to different characteristic information, and in an implementation manner, the corresponding relationship between each type of information and each characteristic information may be pre-stored, so that after the type of information is determined, the corresponding relationship may be searched to obtain the characteristic information corresponding to the determined type of information.
In one implementation, the electronic device may randomly generate the amount of test data, such as generating random numbers 1000, 2000, and so on. The number of the test data corresponding to at least one of the mobile phone number, the person name, the enterprise name, the organization code, the enterprise unified social credit code and the enterprise registration number can be randomly generated. The number of the test data corresponding to different types of information may be the same or different.
In another implementation, a quantity input option may be provided; and receiving the quantity of the test data to be generated, which is input by the user through the quantity input option. I.e. may be understood as specifying for the user the amount of test data generated. If the number of the generated mobile phone numbers is specified, the number of the mobile phone numbers to be generated can be input in the number input options provided by the electronic equipment. For example, the number of names to be generated may be input in a number input option provided by the electronic device. For example, the number of the generated business names may be input in the number input option provided by the electronic device. If the number of generated organization codes is specified, the number of organization codes to be generated can be input in a quantity input option provided by the electronic device. For example, the number of the enterprise unified social credit codes to be generated may be input in the number input option provided by the electronic device. For example, the number of the enterprise registration numbers to be generated can be input in the number input option provided by the electronic device.
S104, generating the quantity of test data meeting the characteristic information.
In one implementation, the electronic device may randomly generate test data satisfying the characteristic information, such as a random number segment generating a mobile phone number; random area codes generate cell phone numbers, random generation of business names ending with limited, etc. Specifically, the generation rule of each characteristic information may be stored in advance, and in the process of generating the test data, the pre-stored rule is acquired first, and the test data satisfying the characteristic information is generated according to the rule.
In the embodiment of the invention, surnames of common surnames, such as 500 surnames and 2 ten thousand common Chinese characters can be pre-recorded as first names, when the test data to be generated comprises the names, one surname can be randomly selected from the surnames, one combination of the Chinese characters can be randomly selected to obtain one name, and the process is repeated to obtain a plurality of names.
In another implementation, a page including property information may be provided; receiving characteristic data which is input by a user on a page and meets characteristic information; and generating test data according to the characteristic data and the quantity of the test data to be generated.
The characteristic data can be understood as specific data corresponding to the characteristic information, for example, the characteristic data corresponding to the number segment in the mobile phone number can be 152, 188, and so on.
It can be understood that one or more fields in the characteristic information are specified for the user, and if the type information includes a mobile phone number, a mobile phone number for generating a certain number segment may be specified, that is, a certain number segment specified by the user input in a page including the characteristic information is, for example, 153 and 153 are characteristic data corresponding to the number segment, and then test data may be generated according to the characteristic data and the number of test data to be generated, that is, a mobile phone number with the number segment of 153 is generated. Or, the generation of the mobile phone number of a certain city may be specified, that is, a specified area code is input by the user in the page including the feature information, the input content is the feature data corresponding to the area code, and then the test data may be generated according to the feature data and the number of the test data to be generated, that is, the mobile phone number of which the area code is the specified area code is generated. The generation of a name of 2 words or 3 words or the use of a name such as a compound name can be specified, and the method can be used for generating data required in special case verification. That is, the user inputs the number of words of the specified person name or the number of words of the last name in the page including the characteristic information, and the input content is the characteristic data corresponding to the number of words of the person name or the number of words of the last name, the test data, that is, the name whose area is encoded as the number of words of the specified person name or the number of words of the last name, can be generated according to the characteristic data and the number of the test data to be generated. The registration management department, the organization type, and the administrative region may be designated, and the generation amount may be designated. Administrative areas, business categories, etc. may be specified.
Fig. 3 is another flowchart of a test data generation method according to an embodiment of the present invention. Referring to fig. 3, after generating the number of test data satisfying the characteristic information, the method may further include:
and S105, encrypting the test data in a preset encryption mode.
The preset encryption mode may be md5 (message digest algorithm), sha256 (hash value length is 256 bits), or sm3 (hash algorithm for adding a fixed-length fingerprint to data).
And S106, importing the encrypted test data into the hbase database.
And directly converting the generated data into batch hbase to be imported into a database.
In this manner, the security of the generated test data may be increased.
In the existing mode, a method for adding data in an hbase library by a tester generally adopts manual input of put sentences, only 1 sentence can be imported each time, the method can automatically convert the corresponding import put sentences according to a plaintext information list, and then the hbase shell imports the corresponding import put sentences in batch, so that the data can be warehoused in batch, and the data import efficiency is improved.
In the embodiment of the invention, a type selection option can be provided for a user to select, so that type information aiming at the type selection option can be received; and further determining characteristic information corresponding to the type information, determining the number of test data to be generated, and generating the test data of which the number of the test data to be generated meets the characteristic information. The method and the device can realize batch automatic generation of a plurality of test data, effectively improve the test efficiency, reduce the test time cost and realize generation of various types of test data.
The problem of generating test data during testing is solved, the test data of types such as personal and enterprise information can be randomly generated in batches for testing, and the test data can be deleted after the testing is finished.
In addition, in an optional embodiment, the test data generation method provided in the embodiment of the present invention is applied to a server, and when the terminal needs to apply the test data generated by the server, the terminal may download the test data from the server to the local terminal, that is, support downloading the data to the local terminal, which may reduce the pressure on the terminal, and so on.
According to the embodiment of the invention, the generated quantity and the characteristics (information such as administrative codes, number sections and the like) of the test data to be generated can be selected simply, conveniently and quickly through a very intuitive page, and the default is random.
Corresponding to the test data generation method provided in the foregoing embodiment, an embodiment of the present invention further provides a test data generation apparatus, as shown in fig. 4, which may include:
a providing module 401 for providing a type selection option;
a receiving module 402, configured to receive type information for the type selection option;
a determining module 403, configured to determine characteristic information corresponding to the type information and determine the number of test data to be generated;
a generating module 404, configured to generate the number of test data that satisfy the characteristic information.
Optionally, the generating module 404 is specifically configured to provide a page including the characteristic information; receiving characteristic data which is input by a user on a page and meets characteristic information; and generating the test data meeting the characteristic data according to the characteristic data and the quantity of the test data to be generated.
Optionally, the determining module 403 is specifically configured to provide a quantity input option; and receiving the quantity of the test data to be generated, which is input by the user through the quantity input option.
Optionally, the type information includes at least one of the following information: mobile phone number, name of person, name of enterprise, organization code, unified social credit code of enterprise, and registration number of enterprise.
Optionally, when the type information includes a mobile phone number, the feature information includes a number segment, a region code, and a user number field;
when the type information comprises an organization code, the characteristic information comprises an enterprise body code and a check code;
when the type information comprises an enterprise unified social credit code, the characteristic information comprises: registering a management department code, an organization type code, an administrative region code of a registration management authority, an organization code and a check code;
when the type information includes an enterprise registration number, the characteristic information includes an administrative code, an enterprise category code, a sequence number and a check code.
Optionally, as shown in fig. 5, the apparatus further includes:
the encryption module 405 is configured to encrypt the test data in a preset encryption manner after the number of test data satisfying the characteristic information is generated;
and an importing module 406, configured to import the encrypted test data into the hbase database.
An embodiment of the present invention further provides an electronic device, as shown in fig. 6, including a processor 601, a communication interface 602, a memory 603, and a communication bus 604, where the processor 601, the communication interface 602, and the memory 603 complete mutual communication through the communication bus 604.
A memory 603 for storing a computer program;
the processor 601 is configured to implement the method steps of the test data generation method provided in the foregoing embodiment when executing the program stored in the memory 603.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In a further embodiment provided by the present invention, a computer-readable storage medium is further provided, in which a computer program is stored, and the computer program, when executed by a processor, implements the method steps of the test data generation method provided by the above-mentioned embodiment.
In a further embodiment provided by the present invention, there is also provided a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method steps of the test data generation method provided by the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, 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 process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.