Test data generation methods, devices, electronic equipment and storage media
By connecting to the database to obtain metadata, constructing contextual prompts and data generation paradigms, the problem of poor flexibility in generating test data by traditional script tools is solved. This enables the generation of test data that conforms to business rules and database structure, thereby improving the accuracy and efficiency of test data.
Patent Information
- Application Number
- CN202611320203.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-11-17
AI Technical Summary
Traditional script tools generate test data with poor flexibility, making it difficult to cope with complex business scenarios. This results in test data that does not closely match real business scenarios and has low accuracy.
By connecting to the target database, obtaining metadata and parsing the database structure, constructing contextual prompts and data generation paradigms, generating test data that conforms to business rules and database structure, and optimizing the data generation process using multi-threaded concurrency mechanisms and conflict detection.
This improved the accuracy of test data generation, ensuring that the generated data conforms to real business scenarios and database rules, thereby enhancing the reliability and efficiency of software testing.
Smart Images

Figure CN123114967A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and is applied to the fields of fintech and healthcare, and particularly to a test data generation method, apparatus, electronic device, and storage medium. Background Technology
[0002] In related technologies, test data is used to verify software functionality, evaluate performance, and verify software security. Taking a fintech scenario as an example, account data from normal transactions, large transfers, and currency exchanges are used to verify the system's accounting functions. Taking a healthcare scenario as an example, registration data containing patient information, available appointment slots, and appointment times are used to evaluate the concurrent performance of a healthcare system in a multi-user appointment registration scenario.
[0003] Software testing relies on scripting tools to generate test data. However, traditional scripting tools lack flexibility, can only generate test data in a fixed format, and struggle to handle complex business scenarios. This results in generated test data that does not closely match real-world business situations, leading to low accuracy in test data generation. Summary of the Invention
[0004] The main objective of this application is to provide a test data generation method, apparatus, electronic device, and storage medium, aiming to improve the accuracy of test data generation.
[0005] To achieve the above objectives, a first aspect of this application proposes a test data generation method, the method comprising: Connect to the target database based on the pre-configured database connection information; Obtain metadata from the connected target database, and parse the metadata to obtain the database structure of the target database; Acquire data to generate requirement text; Based on the data, generate requirement text and construct contextual prompts using the database structure; A data generation paradigm is generated based on preset business rules and the context prompts, and data is constructed according to the data generation paradigm to obtain a business data object. Convert the business data object into a data insertion statement; Test data is generated by executing the data insertion statement on the connected target database.
[0006] In some embodiments, converting the business data object into a data insertion statement includes: Perform conflict detection on the business data object to obtain the conflict detection result; If the conflict detection result indicates that the business data object has a conflict, then the business data object is updated to obtain the target data object; If the conflict detection result indicates that the business data object does not have a conflict, then the business data object is identified as the target data object; Convert the target data object into the data insertion statement.
[0007] In some embodiments, converting the target data object into the data insertion statement includes: Obtain the number of objects in the target data object; If the number of objects reaches a preset threshold, then all the target data objects are formatted to obtain the data insertion statement.
[0008] In some embodiments, the data generation requirement text includes the data generation quantity, and the data construction according to the data generation paradigm to obtain business data objects includes: The task is split according to the amount of data generated, resulting in at least two data generation tasks; Each of the data generation tasks is stored in a task queue; A thread is obtained from a preset thread pool, and the data is retrieved from the task queue through the thread to generate a task, thus obtaining the target generation task; The target generation task is constructed according to the data generation paradigm to obtain the business data object.
[0009] In some embodiments, obtaining threads from a preset thread pool includes: Compare the number of data generated with a preset threshold number; If the amount of data generated is less than the preset threshold, then the thread mode is determined to be the normal working mode; If the amount of data generated is greater than or equal to the preset threshold, then the thread mode is determined to be a producer-consumer mode. The thread is obtained from the preset thread pool according to the normal working mode or the production-consumption mode.
[0010] In some embodiments, before generating test data by executing the data insertion statement through the connected target database, the method further includes: Obtain the index building configuration parameters of the target database; Based on the index construction configuration parameters, an insertion prompt message is sent to the connected target database; Receive pause index building information from the target database based on the insertion prompt information; The data insertion statement is sent to the target database based on the paused index building information.
[0011] In some embodiments, after generating test data by executing the data insertion statement through the connected target database, the method further includes: Obtain target test data and test cases; wherein the target test data is generated by executing the data insertion statement in the target database; Software testing is performed based on the target test data and the test cases.
[0012] To achieve the above objectives, a second aspect of this application provides a test data generation apparatus, the apparatus comprising: The interception module is used to intercept database connection requests from applications. The determination module is used to determine the target database based on the database connection request, obtain the proxy configuration information of the target database, and determine the target database as a proxy database based on the proxy configuration information; The first creation module is used to create a proxy connection object for the proxy database, determine the proxy server, and establish a proxy connection link between the proxy connection object and the proxy server. The second creation module is used to create a proxy statement object through the proxy connection object, and to intercept business requests sent by the application to the proxy database through the proxy statement object. The sending module is used to send the service request to the proxy server for execution through the proxy connection link.
[0013] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.
[0014] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.
[0015] The test data generation method, device, electronic device, and computer-readable storage medium proposed in this application connect to a target database based on database connection information. Metadata is obtained from the connected target database, and the metadata is parsed to obtain the database structure. Test data generation is then constrained based on this database structure, resulting in valid data conforming to database table rules. A data generation requirement text is obtained, explicitly expressing the test data generation needs. Contextual prompts are constructed based on the data generation requirement text and the database structure. Data generation rules conforming to the business rules are generated based on the business rules and the contextual prompts, resulting in a data generation paradigm. Data is constructed according to the data generation paradigm to generate data that fits the real business scenario, resulting in a business data object. Since the business data object is structured data in memory and cannot be directly written to the database, it is converted into a database-recognizable data insertion statement. This data insertion statement is executed through the connected target database to generate valid, database-ready test data. The embodiments of this application generate test data based on business rules, data generation requirement text, and database structure constraints, so that the generated test data simultaneously meets the business logic, test scenario requirements, and database structure, thereby conforming to real business scenarios and avoiding test data that does not conform to business logic, test requirements, or database structure, thus improving the accuracy of test data generation. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of the application environment for the test data generation method provided in the embodiments of this application; Figure 2 This is a flowchart of the test data generation method provided in the embodiments of this application; Figure 3 yes Figure 2 The flowchart of step S250 in the text; Figure 4 yes Figure 3 The flowchart of step S330 in the process; Figure 5 yes Figure 2 The flowchart of step S260 in the text; Figure 6 yes Figure 5 The flowchart of step S540 in the text; Figure 7 This is another flowchart of the test data generation method provided in the embodiments of this application; Figure 8 This is another flowchart of the test data generation method provided in the embodiments of this application; Figure 9 This is a schematic diagram of the test data generation device provided in the embodiments of this application; Figure 10 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0019] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0020] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0021] In related technologies, test data is used to verify software functionality, evaluate performance, and enhance security. For example, in fintech scenarios, account data from normal transactions, large transfers, and currency exchanges are used to verify the accounting functions of financial business systems. In healthcare scenarios, registration data containing patient information, available appointment slots, and appointment times are used to evaluate the concurrent performance of healthcare business systems in multi-user appointment registration scenarios.
[0022] Software testing relies on scripting tools to generate test data. However, traditional scripting tools lack flexibility and can only generate test data in a fixed format, making it difficult to handle complex business scenarios, such as multi-table joins and specific condition combinations. This results in generated test data that does not closely match real-world business scenarios, leading to low accuracy in test data generation.
[0023] Based on this, embodiments of this application provide a test data generation method, a test data generation device, an electronic device, and a computer-readable storage medium, aiming to improve the accuracy of test data generation.
[0024] The test data generation method, test data generation device, electronic device, and computer-readable storage medium provided in this application are specifically described through the following embodiments. First, the test data generation method in this application embodiment is described.
[0025] The test data generation method provided in this application relates to the field of artificial intelligence technology. This test data generation method can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the test data generation method, but is not limited to the above forms.
[0026] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0027] The test data generation method provided in this application embodiment can be applied to, for example, Figure 1In the application environment shown, the client communicates with the server via a network. The server can configure database connection information through the client, connect to the target database according to the database connection information, obtain metadata from the connected target database, parse the metadata to obtain the database structure of the target database, obtain the data generation requirement text, construct context prompts based on the data generation requirement text and database structure, generate a data generation paradigm based on business rules and context prompts, construct data according to the data generation paradigm to obtain business data objects, convert the business data objects into data insertion statements, and execute the data insertion statements through the connected target database to generate test data. In this application, by introducing a database structure, the test data generated according to the database structure constraints conforms to the database table rules, ensuring the validity of the generated test data. Context prompts are constructed based on the data generation requirement text and database structure. A data generation paradigm that conforms to both business rules and data generation requirements is generated according to the business rules and context prompts. Data that fits the real business scenario is generated according to the data generation paradigm. The data is stored in the database to form database test data, simulating various types of data in real business scenarios, thus improving the accuracy of test data generation. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The following detailed description uses specific embodiments to illustrate this application.
[0028] Figure 2 This is an optional flowchart of the test data generation method provided in the embodiments of this application. Figure 2 The method may include, but is not limited to, steps S210 to S270.
[0029] Step S210: Connect to the target database according to the pre-configured database connection information; Step S220: Obtain metadata from the connected target database and parse the metadata to obtain the database structure of the target database; Step S230: Obtain data and generate requirement text; Step S240: Generate requirement text and construct contextual prompts based on the data and database structure; Step S250: Generate a data generation paradigm based on preset business rules and contextual prompts, and construct data according to the data generation paradigm to obtain a business data object; Step S260: Convert the business data object into a data insertion statement; Step S270: Generate test data by executing a data insertion statement through the connected target database.
[0030] Steps S210 to S270, as illustrated in this embodiment, express test data generation requirements using data generation requirement text and describe database table rules using database structure. Contextual prompts are constructed based on the data generation requirement text and database structure. A data generation paradigm that simultaneously conforms to database table rules, test data generation requirements, and business rules is generated based on business rules and contextual prompts. Data is constructed according to the data generation paradigm to create data that fits real business scenarios, resulting in business data objects. These business data objects are converted into database-recognizable data insertion statements. Test data is generated by executing these statements through the target database to simulate various test data from real business scenarios, thus improving the accuracy of test data generation.
[0031] In step S210 of some embodiments, database connection information is pre-configured on the front-end page of the test data generation and management platform, and a target database is connected according to the database connection information. The database connection information includes parameters used by the test data generation and management platform to connect to the database, such as the database address, name, port number, and the account and password of the test data generation and management platform. The target database is the database indicated by the database connection information.
[0032] In step S220 of some embodiments, the metadata interface provided by the platform is invoked to read metadata from the connected target database. The metadata describes the database structure and objects of the target database. The database structure defines the data organization, storage method, relationships and constraints between data, and objects are logical entities that define and store data in the database. Table structure information such as table name, field name, field type, field length, primary key, comments, indexes, and nullability is extracted from the metadata. This table structure information is encapsulated into structured objects to convert the metadata into business-usable structured data, thus obtaining the database structure of the target database. The database structure includes table name, field name, field type, field length, primary and foreign key constraints, and index information, etc.
[0033] For example, for a database table storing transaction log data, its table name can be "Transaction Log Table"; field names can be transaction order number, receiving account, sending account, transaction amount, transaction time, etc.; field types are used to define the data storage format, such as the transaction order number, receiving account, and sending account being integer types, the transaction amount being a fixed-point number type, and the transaction time being a date and time type; primary and foreign key constraints are used to constrain the data corresponding to the field names, such as the transaction order number being the primary key, the receiving account and sending account being foreign keys, the transaction amount being non-nullable, and the transaction time being the default transaction completion time; index information refers to the information of the index created for the field name, including the index name, index type (unique index, normal index, primary key index), etc., such as the index name for the transaction order number being idx_order, and the index type being a unique index.
[0034] The database structure can be converted into JSON or XML format and stored in the platform's memory or cache for use in subsequent steps.
[0035] In step S230 of some embodiments, test data generation requirements are input on the platform's front-end page via voice, text, or other means to generate data generation requirement text. The data generation requirement text can be described using natural language, such as generating insurance application data for a 50-year-old woman or generating medical records for a diabetic patient. The data generation requirement text can also be described using Structured Query Language (SQL) to form a basic query example SQL.
[0036] The data generation requirement text includes the data generation quantity. The data generation quantity refers to the number of test data sets to be generated. For example, the data generation requirement text might read: "Generate 10 valid insurance policies in region A," where 10 represents the data generation quantity.
[0037] In step S240 of some embodiments, traditional scripting tools typically can only generate test data in a fixed format, lacking flexibility and struggling to handle complex test scenarios, such as specific condition combinations and multi-table joins. Taking cross-bank transfers as an example, test data needs to be generated that meets multiple conditions, including a normal user status, sufficient account balance, and available transfer channels. This data involves multiple related tables such as user tables, account tables, and risk control rule tables. Traditional scripting tools cannot generate test data suitable for this scenario.
[0038] To generate test data adapted to the test scenario, a large language model is used to extract semantic features from the data generation requirement text to understand the test requirements and obtain requirement semantic features. Requirement semantic features are key semantic information extracted from the data generation requirement text, used to describe the data generation rules, and can include the names of the data tables involved in data generation, filtering conditions, and the expected data volume. The requirement semantic features and the database structure are then concatenated to form contextual cue words.
[0039] In step S250 of some embodiments, business rules are introduced to constrain data values, field formats, multi-table relationships, and business execution logic, ensuring that the generated test data conforms to the business logic. The design of business rules is related to specific business scenarios. Taking health insurance as an example, the business rules are health insurance business rules, including age restrictions, insurance type rules, premium calculation formulas, etc. The business rules and contextual prompts are concatenated and input into a large language model. The large language model understands the business logic and data generation requirements, and analyzes the business logic relationships between fields, such as the relationship between the age field and the insured amount field. Data generation rules conforming to the business logic are generated, resulting in a data generation paradigm. The data generation paradigm guides the construction and filling of test data.
[0040] The data construction engine constructs data entities with business meaning according to the data generation paradigm, resulting in business data objects. Taking a full refund scenario as an example, it can generate a business data object that includes the entire process from underwriting status → triggering a refund application → generating a refund calculation statement → updating the policy status to refunded.
[0041] During the data construction process, for enumerated data such as gender and education level, data can be randomly selected from a preset dictionary; for numerical data, data can be randomly generated within the constraints of business rules; and for relational data, dependency table data can be generated through recursive logic.
[0042] Please see Figure 3 In some embodiments, step S250 may include, but is not limited to, steps S310 to S340: Step S310: Split the task according to the amount of data generated to obtain at least two data generation tasks; Step S320: Store each data generation task in the task queue; Step S330: Obtain a thread from a preset thread pool, and generate a task by retrieving data from the task queue through the thread to obtain the target generated task; Step S340: Construct data for the target generation task according to the data generation paradigm to obtain business data objects.
[0043] In step S310 of some embodiments, if the number of data generated is greater than or equal to a preset threshold, the current task is determined to be a large-scale data generation task. To alleviate the write load on the target database and avoid resource congestion caused by large batches of submissions, the overall task is split into multiple small, independent subtasks to obtain data generation tasks. Data generation and data ingestion are then completed in batches based on these data generation tasks. The preset threshold refers to a threshold set to achieve task splitting; it is an integer greater than 0 and can be set according to actual conditions. For example, the preset threshold is 10 million.
[0044] For example, if the data generation quantity is 10 million and the preset quantity threshold is 10 million, the data generation quantity is split into 1,000 data generation tasks according to a fixed partitioning method such as 10,000, and each data generation task needs to generate 10,000 data.
[0045] In step S320 of some embodiments, a large number of tasks are generated in a short period of time during peak testing periods. If the tasks are executed synchronously immediately after generation, the sudden surge in traffic will instantly put concurrent pressure on downstream services. To alleviate the concurrent pressure caused by the synchronous serial execution of tasks, a task queue is introduced to decouple task generation from task processing. Specifically, all data generation tasks are stored in the task queue. Alternatively, a task identifier is set for each data generation task, which is used to uniquely distinguish different tasks, and each data generation task is stored in the task queue in sequence according to the task identifier. In some examples, the task identifier can also be used to indicate the task priority of the data generation task, and each data generation task can be stored in the task queue in sequence according to the task priority.
[0046] In step S330 of some embodiments, idle threads are obtained from a preset thread pool, and each idle thread obtains a data generation task from the task queue to obtain the target generation task. Idle threads are active threads that have no tasks to execute and are waiting for new tasks.
[0047] In step S340 of some embodiments, the thread executes the target generation task, calls the data construction engine to construct data entities with business meaning according to the data generation paradigm, and obtains business data objects.
[0048] Steps S310 to S340 above employ a multi-threaded concurrency mechanism to execute the data generation task in parallel, which can make full use of the system's computing power resources, significantly shorten the time required to generate large batches of test data, and thus improve the efficiency of data generation.
[0049] Please see Figure 4 In some embodiments, step S330 may include, but is not limited to, steps S410 to S440: Step S410: Compare the number of data generated with the preset number threshold; Step S420: If the number of data generated is less than the preset threshold, then the thread mode is determined to be the normal working mode. Step S430: If the number of data generated is greater than or equal to a preset threshold, then the thread mode is determined to be the producer-consumer mode. Step S440: Obtain threads from the preset thread pool according to the normal working mode or the producer-consumer mode.
[0050] In step S410 of some embodiments, the number of data generated is compared with a preset number threshold to determine the size relationship between the two.
[0051] In step S420 of some embodiments, the thread mode includes a normal working mode and a producer-consumer mode. The normal working mode refers to a mode where each thread operates completely in parallel, independent of the others, and completes the entire business process independently. The producer-consumer mode refers to a mode where thread roles are divided into producers and consumers, with the two types of threads having separate and isolated tasks. If the amount of data generated is less than a preset threshold, indicating a small data generation scale, the thread mode is determined to be the normal working mode.
[0052] In step S430 of some embodiments, if the number of data generated is greater than or equal to a preset number threshold, it indicates that the data generation scale is large. In order to improve the data generation efficiency, the thread mode is determined to be the production-consumption mode.
[0053] In step S440 of some embodiments, in normal working mode, worker threads are obtained from a preset thread pool, and each worker thread independently executes a data generation task. In producer-consumer mode, producer threads are obtained from the preset thread pool to execute data generation tasks for data construction. After the data generation task is completed, the thread is returned to the thread pool for reuse. Worker threads are threads that wait for and execute tasks, while producer threads are threads that obtain tasks from the task queue and execute them.
[0054] Steps S410 to S440 above distinguish between thread modes: normal working mode and production-consumption mode. Normal working mode is enabled in small-scale data generation scenarios to reduce the concurrent synchronization overhead caused by thread scheduling and data transfer. Production-consumption mode is enabled in large-scale data generation scenarios to improve data generation efficiency.
[0055] In step S260 of some embodiments, the business data object is structured data in memory and cannot be directly written to the database. Therefore, the business data object is converted into a data insertion statement that can be executed by the target database.
[0056] Please see Figure 5In some embodiments, step S260 may include, but is not limited to, steps S510 to S540: Step S510: Perform conflict detection on the business data object and obtain the conflict detection result; Step S520: If the conflict detection result indicates that there is a conflict in the business data object, then the business data object is updated to obtain the target data object; Step S530: If the conflict detection result indicates that there is no conflict in the business data object, then the business data object is determined as the target data object. Step S540: Convert the target data object into a data insertion statement.
[0057] In step S510 of some embodiments, a rule validator is invoked. The rule validator is pre-configured with conflict verification rules. Conflict detection is performed on the business data object according to these rules to obtain a conflict detection result. The conflict detection result indicates whether the business data object has a conflict or not. Conflict verification rules include business constraint rules and physical constraint rules of the target database. Business constraint rules can be customized according to the business scenario, such as prohibiting multiple identical medical insurance settlement statements from being generated for the same patient within a single day. Physical constraint rules are storage constraints defined on the database table structure, such as primary key constraints and unique index constraints.
[0058] In step S520 of some embodiments, if the conflict detection result indicates that there is a conflict in the business data object, the conflict type of the business data object, such as primary key duplication, uniqueness constraint conflict and conflict field, is extracted from the conflict detection result, and the conflict field is corrected according to the conflict type to obtain the target data object.
[0059] In step S530 of some embodiments, if the conflict detection result indicates that there is no conflict in the business data object, then the business data object is used as the target data object.
[0060] In step S540 of some embodiments, the Object Relational Mapping (ORM) component is invoked to convert the target data object into an executable data insertion statement for the target database based on the object mapping relationships built into the ORM. The object mapping relationships are used to indicate the mapping relationship between business data objects and data tables, fields, etc., in the target database.
[0061] Through the above steps S510 to S540, a data insertion statement can be obtained, which can be used to generate test data in the database and realize the reuse of test data.
[0062] Please see Figure 6In some embodiments, step S540 may include, but is not limited to, steps S610 to S620: Step S610: Obtain the number of objects in the target data object; In step S620, if the number of objects reaches a preset threshold, the format of all target data objects is converted to obtain the data insertion statement.
[0063] In step S610 of some embodiments, the premise of batch insertion is that the table names of the data objects are the same and the same fields exist. In order to generate batch insertion statements, the table names and field names of the target data objects are extracted, the number of target data objects with the same table names and the same field names is counted, and the number of objects is obtained.
[0064] In step S620 of some embodiments, if the number of objects equals a preset threshold, the target data objects with the same table name and the same field names are formatted and integrated into a batch input statement to obtain a data insertion statement. The preset threshold is the amount of data to be inserted in the batch. For example, the preset threshold is 500, which means 500 target data objects can be merged into a batch insertion statement. The batch insertion statement can be represented as: INSERT INTO table(field1,field2) VALUES (v1,v2),(v3,v4),(v5,v6), where field1 and field2 are the field names of the fields that have the same field in each target data object, and (v1,v2),(v3,v4),(v5,v6) are the field values of the fields that have the same field in each target data object.
[0065] In normal working mode, steps S610 to S620 can be executed by worker threads. In producer-consumer mode, threads are divided into producer threads and consumer threads, which perform different tasks. Steps S610 to S620 can be executed by consumer threads, which are threads that perform batch format conversions.
[0066] Steps S610 to S620 above assemble the constructed data objects into high-performance batch insert statements to generate large batches of test data based on the batch insert statements.
[0067] In step S270 of some embodiments, a data insertion statement is executed through the connected target database to generate test data in the target database.
[0068] To prevent excessively large transactions from causing database rollback segment overflow, the platform employs a batch transaction commit strategy. Each individual data insert statement is committed independently immediately after execution. If an exception occurs during the data writing process, only the current data insert statement needs to be rolled back; successfully inserted test data will be fully preserved, preventing the complete loss of all inserted test data.
[0069] Please see Figure 7 In some embodiments, prior to step S270, the test data generation method may include, but is not limited to, steps S710 to S740: Step S710: Obtain the index building configuration parameters for the target database; Step S720: Send an insertion prompt message to the connected target database according to the index building configuration parameters; Step S730: Receive pause index building information from the target database based on the insertion prompt information; Step S740: Send a data insertion statement to the target database based on the paused index building information.
[0070] In step S710 of some embodiments, before executing the data insertion statement, the index building configuration parameters of the target database are obtained. The index building configuration parameters are used to indicate whether the target database supports or does not support index building.
[0071] In step S720 of some embodiments, if the index building configuration parameters indicate that the target database supports index building, an insertion prompt message is sent to the connected target database to indicate that the target database is about to insert data into it.
[0072] In step S730 of some embodiments, the data table index is updated synchronously during data insertion, generating a large number of I / O operations. To reduce the disk I / O overhead of writing data to the database, index building needs to be paused in advance. Specifically, the target database pauses the data table index building based on the insertion prompt information, generates pause index building information, and feeds the pause index building information back to the platform.
[0073] In step S740 of some embodiments, after receiving the pause index building information, the platform sends a data insertion statement to the target database, causing the target database to execute the data insertion statement and generate test data. After the data insertion statement is executed, the index building of the data table continues.
[0074] Steps S710 to S740 above, which pause table index building before inserting data into the database, can significantly reduce disk I / O overhead during the write phase.
[0075] Please see Figure 8 In some embodiments, after step S270, the test data generation method may also include, but is not limited to, steps S810 to S820: Step S810: Obtain target test data and test cases; wherein, the target test data is generated by executing data insertion statements in the target database; Step S820: Perform software testing based on the target test data and test cases.
[0076] In step S810 of some embodiments, target test data is obtained by executing data insertion statements in the target database to generate test data, and test cases matching the target test data are obtained. The target test data is the generated data used to simulate real business scenarios.
[0077] In step S820 of some embodiments, test cases are executed, and target test data matching the test cases is loaded. Software testing is then performed based on the target test data and the test cases, thereby improving software quality. Types of software testing may include functional testing, performance testing, compatibility and migration testing, and boundary and exception testing, etc.
[0078] Steps S810 to S820 above utilize test data that aligns with business scenarios for software testing, which can improve the reliability of software testing and thus improve software quality.
[0079] Please see Figure 9 This application also provides a test data generation apparatus that can implement the above-described test data generation method. The test data generation apparatus includes: Connection module 910 is used to connect to the target database according to pre-configured database connection information; The parsing module 920 is used to obtain metadata from the connected target database and parse the metadata to obtain the database structure of the target database. Module 930 is used to acquire data and generate the required text. The prompt word construction module 940 is used to generate requirement text and construct context prompt words based on data and database structure; The data construction module 950 is used to generate a data generation paradigm based on preset business rules and contextual prompts, and to construct data according to the data generation paradigm to obtain business data objects. The conversion module 960 is used to convert business data objects into data insertion statements. The generation module 970 is used to generate test data by executing data insertion statements through the connected target database.
[0080] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described test data generation method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0081] Please see Figure 10 , Figure 10The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 1010 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 1020 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010 using the test data generation method of the embodiments of this application. The input / output interface 1030 is used to implement information input and output; The communication interface 1040 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 1050 transmits information between various components of the device (e.g., processor 1010, memory 1020, input / output interface 1030, and communication interface 1040); The processor 1010, memory 1020, input / output interface 1030 and communication interface 1040 are connected to each other within the device via bus 1050.
[0082] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described test data generation method.
[0083] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0084] The test data generation method, device, electronic device, and computer storage medium provided in this application embodiment express test data generation requirements using data generation requirement text and describe database table rules using database structure. Contextual prompts are constructed based on the data generation requirement text and database structure. A data generation paradigm that simultaneously conforms to database table rules, test data generation requirements, and business rules is generated based on business rules and contextual prompts. Data is constructed according to the data generation paradigm to create data that fits real business scenarios, resulting in business data objects. The business data objects are converted into database-recognizable data insertion statements. Test data is generated by executing these data insertion statements through the target database to simulate various test data in real business scenarios, thereby improving the accuracy of test data generation.
[0085] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0086] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0087] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0088] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0089] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0090] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0091] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0092] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0093] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0094] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0095] It should be noted that any AI models, software tools, or components not belonging to this company appearing in the embodiments of this application are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this application has been authorized (with the knowledge and consent) by the relevant parties or has been fully authorized by all parties, and the executing entity may obtain it through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.
[0096] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A method for generating test data, characterized in that, The method includes: Connect to the target database based on the pre-configured database connection information; Obtain metadata from the connected target database, and parse the metadata to obtain the database structure of the target database; Acquire data to generate requirement text; Based on the data, generate requirement text and construct contextual prompts using the database structure; A data generation paradigm is generated based on preset business rules and the context prompts, and data is constructed according to the data generation paradigm to obtain a business data object. Convert the business data object into a data insertion statement; Test data is generated by executing the data insertion statement on the connected target database.
2. The method according to claim 1, characterized in that, The step of converting the business data object into a data insertion statement includes: Perform conflict detection on the business data object to obtain the conflict detection result; If the conflict detection result indicates that the business data object has a conflict, then the business data object is updated to obtain the target data object; If the conflict detection result indicates that the business data object does not have a conflict, then the business data object is identified as the target data object; Convert the target data object into the data insertion statement.
3. The method according to claim 2, characterized in that, The step of converting the target data object into the data insertion statement includes: Obtain the number of objects in the target data object; If the number of objects reaches a preset threshold, then all the target data objects are formatted to obtain the data insertion statement.
4. The method according to claim 1, characterized in that, The data generation requirement text includes the data generation quantity, and the data construction according to the data generation paradigm to obtain business data objects includes: The task is split according to the amount of data generated, resulting in at least two data generation tasks; Each of the data generation tasks is stored in a task queue; A thread is obtained from a preset thread pool, and the data is retrieved from the task queue through the thread to generate a task, thus obtaining the target generation task; The target generation task is constructed according to the data generation paradigm to obtain the business data object.
5. The method according to claim 4, characterized in that, The step of obtaining threads from a preset thread pool includes: Compare the number of data generated with a preset threshold number; If the amount of data generated is less than the preset threshold, then the thread mode is determined to be the normal working mode; If the amount of data generated is greater than or equal to the preset threshold, then the thread mode is determined to be a producer-consumer mode. The thread is obtained from the preset thread pool according to the normal working mode or the production-consumption mode.
6. The method according to any one of claims 1 to 5, characterized in that, Before generating test data by executing the data insertion statement through the connected target database, the method further includes: Obtain the index building configuration parameters of the target database; Based on the index construction configuration parameters, an insertion prompt message is sent to the connected target database; Receive pause index building information from the target database based on the insertion prompt information; The data insertion statement is sent to the target database based on the paused index building information.
7. The method according to any one of claims 1 to 5, characterized in that, After generating test data by executing the data insertion statement through the connected target database, the method further includes: Obtain target test data and test cases; wherein the target test data is generated by executing the data insertion statement in the target database; Software testing is performed based on the target test data and the test cases.
8. A test data generation device, characterized in that, The device includes: The connection module is used to connect to the target database based on pre-configured database connection information; The parsing module is used to obtain metadata from the connected target database and parse the metadata to obtain the database structure of the target database. The acquisition module is used to acquire data and generate the required text. The prompt word construction module is used to generate requirement text and construct context prompt words based on the data and the database structure; The data construction module is used to generate a data generation paradigm based on preset business rules and the context prompts, and to construct data according to the data generation paradigm to obtain a business data object. The conversion module is used to convert the business data object into a data insertion statement; The generation module is used to generate test data by executing the data insertion statement through the connected target database.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 7.
