Python-based test data automatic generation method and system

Through the automatic method of generating data based on Python, the problem of generating low efficiency, poor consistency, and high risk of error risk in existing technologies have been solved, and large -scale testing data is achieved efficiently and accurately, and artificial intervention and privacy are reduced Leaks risk.

CN119377082APending Publication Date: 2025-01-28BEIYIN FINANCIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411512018.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-01-28

AI Technical Summary

Technical Problem

The prior art is inefficient in generating simulated data in software development and system testing, poor data consistency, difficult to cover all scenarios, and has a high risk of errors.

Method used

Adopt Python -based test data automatic generating methods, by formulating data generation templates and configuration files, designing data models and generating rules, obtaining and verifying data generation templates and configuration files, recording operations, error information and warnings in the process of generating process, and warning, and warning, and and. Use Python's Faker and Random to form random test data.

Benefits of technology

The large -scale test data is generated efficient and accurately, reducing artificial intervention, increasing data consistency and coverage, and protecting user privacy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119377082A_ABST
    Figure CN119377082A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic test data generation method and system based on Python. The automatic data generation method comprises the steps that a data generation template and a configuration file are formulated, and a data model and a generation rule are designed; obtaining a data generation template and a configuration file, executing a verification data rule, and checking whether the configuration rule accords with a specification or not; recording operation, error information and warning in the generation process; and generating random test data to a specified position or a specified database. The automatic data generation tool can efficiently and accurately generate large-scale test data through flexible configuration and templates and built-in data verification, performance optimization and data security characteristics, manual intervention is reduced, and user privacy is protected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of test data, and in particular to a Python-based test data automatic generation method and system. Background Art

[0002] In the process of software development and system testing, generating simulated data is one of the most important links. High-quality test data can not only help developers and testers conduct more comprehensive and in-depth testing, but also effectively ensure the stability and performance of the software in various situations. Through simulated data, we can simulate actual usage scenarios in different test environments, verify the reliability, responsiveness and processing capabilities of the system, and thus discover and fix potential problems. Data in production environments often contain sensitive information, such as personal identity information, financial data, or company secrets. Directly using real data for testing may lead to data privacy issues and security risks, especially when processing and storing this data, strict data protection regulations and privacy policies need to be followed. Therefore, generating simulated data can effectively avoid these problems. It can provide the necessary data support for various test scenarios while ensuring data privacy and security.

[0003] In the prior art, generating simulation data often requires testers to manually input data or use simple scripts or Excel to generate a small amount of test data. This method is usually used for small-scale testing or specific testing scenarios, and has the following problems:

[0004] Low efficiency: Manual data creation is time-consuming and labor-intensive, making it difficult to generate large amounts of data quickly.

[0005] Poor consistency: Data inconsistency or non-compliance with actual business rules is likely to occur.

[0006] Difficulty covering all scenarios: Manual methods have difficulty covering various data variants and edge cases and may miss some test scenarios.

[0007] High risk of error: Human errors may lead to quality issues in test data and affect the reliability of test results. Summary of the invention

[0008] In view of the above problems, the present invention is proposed to provide a Python-based test data automatic generation method and system that overcomes the above problems or at least partially solves the above problems.

[0009] According to one aspect of the present invention, a method for automatically generating test data based on Python is provided, and the method for automatically generating test data comprises:

[0010] Develop data generation templates and configuration files, design data models and generation rules;

[0011] Obtain data generation templates and configuration files, execute verification data rules, and check whether configuration rules meet specifications;

[0012] Record operations, error messages, and warnings during the build process;

[0013] Generate random test data to a specified location or database.

[0014] Optionally, the formulating of data generation templates and configuration files, designing of data models and generation rules specifically include:

[0015] Specify the type, format and amount of test data tables that need to be generated;

[0016] Constraints between table data;

[0017] Define data fields: define the data fields required for each table;

[0018] Select data type: Specify the appropriate data type for each field;

[0019] Set data distribution: Set data distribution rules according to requirements.

[0020] Optionally, the test data table types include: user table and order table; the formats include: JSON, CSV and SQL; the constraint relationships include: uniqueness, foreign key relationships; the data fields include: user table name, email address, phone number; the data types include: string, integer, date.

[0021] Optionally, the verification data rules include: whether it is a unique constraint, data type, maximum length, value range, and relationship constraints between columns.

[0022] Optionally, the operations, error messages and warnings in the record generation process specifically include:

[0023] If all validation rules are passed, a detailed data generation report is generated, including statistical information and quality analysis of data generation;

[0024] If all validation rules fail: provide error reports and processing suggestions to help users solve problems in the data generation process.

[0025] Optionally, the generating random test data to a specified location or a specified database specifically includes:

[0026] Use Python's faker and random packages to generate random test data to a specified location or database.

[0027] The present invention also provides a Python-based test data automatic generation system, which applies the above-mentioned Python-based test data automatic generation method, and the generation system includes: a data definition module, a data verification module, a data generation module and a data storage module;

[0028] The data definition module is used to formulate data generation templates and configuration files, design data models and generation rules;

[0029] The data verification module is used to obtain data generation templates and configuration files, execute verification data rules, and check whether the configuration rules meet the specifications;

[0030] Data generation module, used to generate specific test data according to data model and field definition;

[0031] The data storage module is used to generate random test data to a specified location or a specified database.

[0032] Optionally, the generation system further includes:

[0033] The log and report module is used to record logs during the data generation process and generate data generation reports.

[0034] The present invention provides a Python-based test data automatic generation method and system, the data automatic generation method includes: formulating data generation templates and configuration files, designing data models and generation rules; obtaining data generation templates and configuration files, executing verification data rules, and checking whether configuration rules meet specifications; recording operations, error messages and warnings during the generation process; generating random test data to a specified location or a specified database. The automated data generation tool can efficiently and accurately generate large-scale test data through flexible configuration and templates, built-in data verification, performance optimization and data security features, reduce manual intervention and protect user privacy.

[0035] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0037] Figure 1 A flowchart of a method for automatically generating test data based on Python provided by an embodiment of the present invention;

[0038] Figure 2 A block diagram of the composition of a Python-based test data automatic generation system provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0040] The terms "comprises" and "having" and any variations thereof in the description embodiments, claims and drawings of the present invention are intended to cover non-exclusive inclusions, for example, including a series of steps or units.

[0041] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.

[0042] like Figure 1 As shown, a method for automatically generating batch test data based on Python includes:

[0043] 1. Develop data generation templates and configuration files, design data models and generation rules, and define the following:

[0044] Specify the test data table type (such as user table, order table, etc.), format (JSON, CSV, SQL, etc.) and data volume to be generated

[0045] Constraints between table data, such as uniqueness, foreign key relationships, etc.

[0046] Define data fields: Define the data fields required for each table, such as name, email, phone number, etc. in the user table.

[0047] Select data type: Specify the appropriate data type (such as string, integer, date, etc.) for each field.

[0048] Set data distribution: Set data distribution rules according to requirements, such as random generation, sequence generation, etc.

[0049] 2. Obtain data generation templates and configuration files, execute verification data rules, and check whether the configuration rules meet the specifications. The rules include: unique constraints, data types, maximum length, value range, and relationship constraints between columns.

[0050] 3. Record operations, error messages, and warnings during the build process to facilitate debugging and tracing.

[0051] If all validation rules are passed, a detailed data generation report is generated, including statistical information and quality analysis of data generation.

[0052] If all validation rules fail: provide error reports and processing suggestions to help users solve problems in the data generation process.

[0053] 4. Use Python's faker, random and other packages to generate random test data to a specified location or database.

[0054] like Figure 2 As shown, a batch test data automatic generation system based on Python includes: a data definition module, a data verification module, a data generation module, a data storage module, a log and report module;

[0055] The data definition module is used to define the structure of the data model and data fields, and specify the rules and format for data generation.

[0056] Design data models and generate rules to define data fields, data types, data distribution and relationships.

[0057] Develop data generation templates and configuration file formats to facilitate user-defined generation requirements.

[0058] Allows the user to configure parameters of data generation.

[0059] Parameter settings: allow users to set the quantity, data type, field content, etc. of generated data.

[0060] Template support: Supports custom data generation templates to generate data according to user needs.

[0061] The data validation module is used to verify whether the data definition conforms to the expected format and rules.

[0062] Format validation: Checks whether the data conforms to a specified format, such as whether an email address is valid or whether a phone number conforms to a specific pattern.

[0063] Completeness Validation: Ensure that all required fields are correctly populated and there are no missing values.

[0064] Consistency validation: Checks the consistency between fields, such as confirming that the date in a date field is within a reasonable range.

[0065] Constraint validation: The relationships and dependencies between data need to be accurately simulated, such as foreign key constraints, data dependencies, etc.

[0066] The data generation module is used to generate specific test data based on the data model and field definition.

[0067] Random Generation: Use random number generation algorithms to generate various field values, such as random names, addresses, dates, etc.

[0068] Parallel processing: Supports multi-threaded or distributed processing to speed up data generation.

[0069] Cache mechanism: Use cache technology to reduce repeated calculations and improve data generation efficiency.

[0070] Load balancing: Load balancing is performed across multiple processing nodes to optimize resource utilization.

[0071] Data constraints: Ensure that the generated data meets certain constraints, such as the email format is correct, the date is within a certain range, etc.

[0072] The data storage module is used to store the generated data for further use or analysis.

[0073] Storage format: Supports different data storage formats, such as CSV, JSON, database, etc.

[0074] File output: Output data to the specified file, supporting batch data export.

[0075] Database Insertion: Insert the generated data directly into the database for database testing.

[0076] The log and report module is used to record logs during the data generation process and generate data generation reports.

[0077] Logging: Records operations, error messages, and warnings during the build process to facilitate debugging and tracing.

[0078] Report Generation: Generate detailed data generation reports including statistics and quality analysis of data generation.

[0079] Error handling: Provide error reports and handling suggestions to help users solve problems in the data generation process.

[0080] Beneficial effects: Automated data generation tools can efficiently and accurately generate large-scale test data through flexible configuration and templates, built-in data validation, performance optimization, and data security features, reducing manual intervention and protecting user privacy.

[0081] The above specific implementation methods further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for automatically generating test data based on Python, characterized in that: The automatic data generation method comprises: Develop data generation templates and configuration files, design data models and generation rules; Obtain data generation templates and configuration files, execute verification data rules, and check whether configuration rules meet specifications; Record operations, error messages, and warnings during the build process; Generate random test data to a specified location or database.

2. The method for automatically generating test data based on Python according to claim 1, characterized in that: The formulation of data generation templates and configuration files, design of data models and generation rules specifically include: Specify the type, format and amount of test data tables that need to be generated; Constraints between table data; Define data fields: define the data fields required for each table; Select data type: Specify the appropriate data type for each field; Set data distribution: Set data distribution rules according to requirements, such as random generation, sequence generation, etc.

3. The method for automatically generating test data based on Python according to claim 2, characterized in that: The test data table types include: user table and order table; the formats include: JSON, CSV and SQL; the constraint relationships include: uniqueness, foreign key relationships; the data fields include: user table name, email address, phone number; the data types include: string, integer, date.

4. The method for automatically generating test data based on Python according to claim 1, characterized in that: The verification data rules include: unique constraint, data type, maximum length, value range, and relationship constraints between columns.

5. The method for automatically generating test data based on Python according to claim 1, characterized in that: The operations, error messages and warnings during the record generation process specifically include: If all validation rules are passed, a detailed data generation report is generated, including statistical information and quality analysis of data generation; If all validation rules fail: provide error reports and processing suggestions to help users solve problems in the data generation process.

6. The method for automatically generating test data based on Python according to claim 1, characterized in that: The generating of random test data to a designated location or a designated database specifically includes: Use Python's faker and random packages to generate random test data to a specified location or database.

7. A Python-based test data automatic generation system, using the Python-based test data automatic generation method according to any one of claims 1 to 6, characterized in that: The generation system includes: a data definition module, a data verification module, a data generation module and a data storage module; The data definition module is used to formulate data generation templates and configuration files, design data models and generation rules; The data verification module is used to obtain data generation templates and configuration files, execute verification data rules, and check whether the configuration rules meet the specifications; Data generation module, used to generate specific test data according to data model and field definition; The data storage module is used to generate random test data to a specified location or a specified database.

8. The Python-based test data automatic generation system according to claim 1, characterized in that: The generation system further comprises: The log and report module is used to record logs during the data generation process and generate data generation reports.