Test case generation method and device, electronic equipment, storage medium and program product
By using the training to convergence database verification statement generation model to automatically generate database test scripts, the problems of low efficiency and poor stability of manual writing test cases are solved, and efficient and stable database change tests are achieved.
Patent Information
- Application Number
- CN202510286243.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-11
- Publication Date
- 2025-08-01
AI Technical Summary
In the prior art, database change testing mainly relies on manual writing of test cases, resulting in low efficiency and unstable results when facing large or complex database data change tasks, and is susceptible to subjective factors of the tester.
By obtaining the target database information and change scripts, the database verification statement generated by training to convergence generates the target verification statement, and automatically generates the target test scripts to ensure the accuracy and diversity of the test scripts.
It improves the efficiency and stability of database change tests, reduces the error caused by manual intervention, and ensures the accuracy and comprehensiveness of the test process.
Smart Images

Figure CN120407393A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to a test case generation method, apparatus, electronic device, storage medium, and program product. Background Art
[0002] As the core component of data management, the database undertakes the important responsibilities of storing and providing data access. To ensure that data can be effectively changed in the database, it is necessary to ensure the accuracy of data changes in the database to avoid business exception problems caused by incorrect data change operations. Database change testing is a key step to ensure the quality, reliability, efficiency, and security of database changes. It covers comprehensive testing from data structure to function, performance, and security, so as to ensure the stability, security, and accuracy of database changes.
[0003] In the prior art, database change testing mainly involves manually writing test cases by testers to verify the test scenarios corresponding to data changes in the database or manually writing test scripts based on an automated test framework for semi-automated data change testing in the database. These methods are only applicable to simple database change testing tasks. When there are a large number or complex database data change testing tasks, the method of manually participating in writing test cases is easily affected by subjective factors of testers, may have errors in the operations of testers, and takes a long time to complete the test tasks, resulting in low test efficiency and unstable test results. Summary of the Invention
[0004] Embodiments of this application provide a test case generation method, apparatus, electronic device, storage medium, and program product to achieve the effect of improving test efficiency and maintaining the stability of test results.
[0005] In a first aspect, an embodiment of this application provides a test case generation method, including:
[0006] Obtain target database information and a target change script corresponding to the database to be tested; the target change script is a script for performing data changes in the database to be tested;
[0007] Determine target change information for changing the data to be tested based on the target change script;
[0008] Judge whether the target change script meets the preset test verification requirements. If it meets the preset test verification requirements, input the target change information into the database verification statement generation model trained to convergence to generate a target verification statement, where the target verification statement is used to verify whether the changed data meets the requirements of the changed data;
[0009] Generate a target test script based on the target database information, the target change information, and the target verification statement; the target test script is used to test the database after data changes.
[0010] In a possible implementation manner, the preset test verification requirements include: syntax verification requirements, change information integrity verification requirements, and consistency requirements between the target change script and the preset change information; the target database information includes: target database type; the target change script contains database operation statements.
[0011] Judging whether the target change script meets the preset test verification requirements includes:
[0012] Execute the database operation statements according to a preset script verification scheme based on the target database type to judge whether the target change script meets the syntax verification requirements.
[0013] Moreover, judge whether the target change information is complete according to a preset information integrity rule to judge whether the target change script meets the change information integrity verification requirements.
[0014] Moreover, obtain the preset change information, and compare the target change information with the preset change information to judge whether the target change script meets the consistency verification requirements.
[0015] If the syntax verification requirements, the change information integrity verification requirements, and the consistency requirements are simultaneously met, it is determined that the target change script meets the preset test verification requirements.
[0016] In a possible implementation manner, generating the target test script based on the target database information, the target change information, and the target verification statement includes:
[0017] Obtain a test scenario that matches the target change information.
[0018] Obtain a test case script template that matches the test scenario; the test case script template includes configuration items.
[0019] Add the target database information and the target verification statement to the configuration items of the test case script template to generate a target test script.
[0020] In a possible implementation manner, the database verification statement generation model is a neural network model; the training steps of the database verification statement generation model trained to convergence include:
[0021] Obtain historical change information; the historical change information includes a historical change operation identifier, a historical change data table name, a historical change field name, and a historical change data type;
[0022] Match a corresponding historical change verification identifier based on the historical change operation identifier;
[0023] Generate a historical verification statement based on the historical change information and the historical verification identifier; there is at least one historical verification statement;
[0024] Use the historical change data table name, the historical change field name, the historical change operation identifier, and the historical change data type as data change features; use the historical verification statement as the label of the training sample;
[0025] Use the data change features and their corresponding training sample labels as training sample data;
[0026] Input the training sample data into an initial neural network model for training until the initial neural network model converges, so as to obtain a database verification statement generation model trained to convergence.
[0027] In a possible implementation manner, it further includes:
[0028] In response to the successful execution of the target test script, store the target change information and its corresponding target verification statement;
[0029] Obtain the stored target change information and its corresponding target verification statement, and update the training sample data based on the target change information and its corresponding target verification statement;
[0030] Optimize the database verification statement generation model trained to convergence based on the updated sample data.
[0031] In a possible implementation manner, the method further includes:
[0032] Generate a target rollback script based on the target change information;
[0033] If the execution of the target change script fails, exit the test and roll back the changed data according to the target rollback script;
[0034] If the execution of the target change script is successful, execute the target test script and generate a test report;
[0035] If the test report shows that the execution of the target test script fails, roll back the changed data according to the target rollback script.
[0036] In a second aspect, an embodiment of the present application provides a test case generation device, including:
[0037] An acquisition module, configured to acquire target database information and a target change script corresponding to a database to be tested; the target change script is a script for executing data changes in the database to be tested;
[0038] A determination module, configured to determine target change information for changing the data to be tested based on the target change script;
[0039] A first generation module, configured to determine whether the target change script meets a preset test verification requirement. If the preset test verification requirement is met, the target change information is input into a database verification statement generation model trained to convergence to generate a target verification statement, where the target verification statement is used to verify whether the changed data meets the requirements of the changed data;
[0040] A second generation module, configured to generate a target test script based on the target database information, the target change information, and the target verification statement; the target test script is used to test the database to be tested after data changes.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0042] The memory stores computer execution instructions;
[0043] The processor executes the computer execution instructions stored in the memory, so that the processor executes various possible implementation manners in the first aspect above.
[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where computer execution instructions are stored in the computer-readable storage medium, and when the computer execution instructions are executed by a processor, they are used to implement various possible implementation manners in the first aspect above.
[0045] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements various possible implementation manners in the first aspect above.
[0046] The test case generation method, device, electronic device, storage medium and program product provided by the embodiments of the present application can determine the accuracy of the current target change script by judging whether the target change script meets the preset test verification requirements, and further can ensure that the data is correctly changed using the target change script; when the target change script meets the preset test verification requirements, it indicates that the target change script meets the test requirements, and then the generated target change information is input into the converged database verification statement generation model to generate the target verification statement; the converged database verification statement generation model can quickly generate rich and accurate target verification statements as the target change information varies; furthermore, when generating the target test script based on the target database information, target change information and target verification statement, the target test script also contains rich and accurate target test statements; finally, using the target test script to perform the test after the data change on the database to be tested can improve the test efficiency and maintain the stability of the test results. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0048] Figure 1 It is an application scenario diagram of the test case generation method provided by the embodiments of the present application;
[0049] Figure 2 It is a flowchart of the test case generation method provided by an embodiment of the present application;
[0050] Figure 3 It is a block diagram of the target test script generation method provided by an embodiment of the present application;
[0051] Figure 4 It is a flow block diagram of the test case generation method provided by an embodiment of the present application;
[0052] Figure 5 It is a schematic diagram of the test case generation device provided by the embodiments of the present application;
[0053] Figure 6 It is a schematic diagram of the structure of the electronic device provided by the embodiments of the present application.
[0054] Through the above accompanying drawings, the clear embodiments of the present application have been shown, and there will be more detailed descriptions hereinafter. These drawings and text descriptions are not intended to limit the scope of the concept of the present application in any way, but to explain the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0055] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0056] First, the terms involved in the present application will be explained:
[0057] Database change: It is a part of the database management process that can make any form of modification to the database, including database structure changes, data changes, and database configuration changes, etc. Its purpose is to meet new business requirements, improve the performance of the database, fix database errors, and adapt to changes in the technical environment.
[0058] Database testing: It refers to various testing activities performed on the database system, aiming to discover and solve problems in the database system, including aspects such as data integrity, data consistency, data security, and performance optimization. This process involves checking the database structure, testing the call relationships between data tables, and evaluating the performance of the database in various operation scenarios.
[0059] Automated testing: It refers to the process of simulating user operations through automated test scripts, tools, and frameworks, automatically executing test cases to test the database, and generating test results and reports.
[0060] To clearly understand the technical solution of the present application, the solutions of the prior art will be introduced in detail first.
[0061] In the prior art, for database change testing, testers mainly manually write test cases to verify the test scenarios corresponding to data changes in the database, or manually write test scripts based on an automated testing framework to perform semi-automated database data change testing. Specifically: testers evaluate the affected test scenarios according to the data changes and their own subjective ideas to determine the test scenarios and test items; then testers manually write and design test cases and execute the test cases according to the test scenarios and test items; or after determining the test scenarios and test items, testers manually write test scripts according to the code format corresponding to the automated testing framework, and the test tool runs the test scripts to implement the testing of data changes in the database. However, these methods are only applicable to simple database change testing tasks. When there are a large number of or complex database data change testing tasks, the method of manually participating in writing test cases is easily affected by the subjective factors of testers, there may be errors in the operations of testers and it takes a long time to complete the testing tasks, resulting in low testing efficiency and unstable test results.
[0062] Therefore, when facing the prior art, in order to enable the target change script to accurately change the data and discover the test failures caused by the target change script as early as possible, the target change script can be checked by presetting test verification requirements. When the target change script meets the preset test specification requirements, the process of generating the target verification statement is carried out; in order to achieve rapid automated generation of the target test script, first rapidly and automatically obtain the target verification statement, and then generate the target test script according to the obtained target change information and target verification statement; and the database verification statement generation model trained to convergence has the characteristics of fast calculation speed and high calculation accuracy, and can generate different target verification statements according to different target change information. Therefore, using the database verification statement generation model trained to convergence can quickly, accurately and diversely predict the target verification statement. Therefore, generating the target test script according to the obtained target database information, target change information and target verification statement is also an accurate and diverse test script. Thus, using the target test script to execute the test after the data in the database to be tested is changed can improve the testing efficiency and maintain the stability of the test results.
[0063] Figure 1 This is an application scenario diagram of the test case generation method provided by the embodiment of the present application. In this scenario, it may include a terminal device 101, a test case generation device 102 and a server 103; the terminal device 101 is communicatively connected to the test case generation device 102; the test case generation device 102 is communicatively connected to the server 103.
[0064] Optionally, the test case generation device 102 can also be integrated into the server 103, or directly in the server 103 and execute the above process of generating the target test script.
[0065] Specifically, the user inputs the database model to be tested into the terminal device 101, and the terminal device 101 sends a test case generation request to the test case generation device 102 and carries the database model to be tested; after the test case generation device 102 receives the test case generation request and the input database model to be tested, the test case generation device 102 sends the database model to be tested to the server 103. The server 103 matches the corresponding target database information and target change script according to the database model to be tested, and sends them to the test case generation device 102; after the test case generation device 102 obtains the target database information and target change script corresponding to the database to be tested, it determines the target change information for changing the data to be tested based on the target change script; and determines whether the target change script meets the preset test verification requirements. If it meets the preset test verification requirements, the target change information is input into the database verification statement generation model trained to convergence to generate a target verification statement, which is used to verify whether the changed data meets the requirements of the changed data; a target test script is generated based on the target change information and the target verification statement; thus, it is possible to implement the test of the database to be tested after the data change by executing the target test script, so as to improve the test efficiency and maintain the stability of the test results.
[0066] The following uses specific embodiments to detail the technical solutions of the present application and how the technical solutions of the present application solve the above technical problems. These specific embodiments below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below with reference to the accompanying drawings.
[0067] Figure 2 It is a flowchart of a test case generation method provided by an embodiment of the present application. As Figure 2 shown, the execution subject of this embodiment is a test case generation device, which can be implemented through a computer program; it can also be implemented through a medium storing relevant computer programs, such as a USB flash drive and / or an optical disc, etc., or can also be implemented through an entity device integrated or installed with relevant computer programs, such as a chip or a test case generation device, etc. The test case generation device can be a server, a server cluster, a terminal device or other electronic devices, etc. The test case generation method provided by this embodiment includes the following steps:
[0068] Step 201: Obtain the target database information and the target change script corresponding to the database to be tested; the target change script is a script for executing data changes in the database to be tested.
[0069] Among them, the target database information refers to the basic information of the database to be tested, which may include: the type of the target database, the name of the target database, the user name for logging in to the target database, the password for logging in to the target database, the address of the target database, and the port number of the target database.
[0070] Among them, the type of the target database refers to the type of the database to be tested; the types of test databases can be My Structured Query Language (abbreviated as mysql), MongoDB (abbreviated as Mongo), Oracle Database (abbreviated as Oracle), or other types of databases, which are not specifically limited in this embodiment.
[0071] Among them, the name of the target database: refers to the name of the database to be tested.
[0072] Among them, the user name for logging in to the target database refers to the user name for logging in to the target database, which is unique.
[0073] Among them, the password for logging in to the target database refers to the password for logging in to the target database, which matches the user name for logging in to the target database.
[0074] The address of the target database refers to the network address for connecting to the database, which is unique.
[0075] The port number of the target database refers to a 16-bit integer used to distinguish the target database. Each port number corresponds to a unique target database. In network communication, data packets can be correctly transmitted to the target database through the port number.
[0076] Among them, the target change script can be a file that is pre-written according to change requirements and contains database operation statements. A target change script can contain multiple database operation statements. Since different databases have different performances, different target change scripts need to be written for different database types, which can be stored in the local folder of the server. Therefore, the content in the corresponding target change script can be accessed through the storage path where the target change script is located. The storage path where the target change script is located consists of the local folder name, the target change script name, and the slash symbol. The local folder name can be defined according to requirements, and the definition method of the target change script name can also be defined according to requirements. In this embodiment, no specific limitation is made, but it is necessary to ensure that the target change script name is unique so that the target change script can be accessed according to the target change script name. Exemplarily, the storage path where the target change script is located can be expressed as " / tmp / v1", where "tmp" represents the local folder name and "v1" represents the target script name. There can be multiple ways to define the storage path where the target change script is located, and no specific limitation is made in this embodiment.
[0077] It can be understood that the target change script can also be a script that is written according to requirements and contains other types of test statements, and there can be multiple forms, which are not specifically limited in this embodiment.
[0078] Optionally, the storage path where the target change script is located and its corresponding database type can be associated and stored in the target change script matching table. The target change script matching table can be a table that stores the storage path where the target change script is located and its corresponding database type, and can also store other data. In this embodiment, no specific limitation is made.
[0079] Among them, the database operation statement can be a statement used to execute data change operations, and the database operation statement can contain target change information.
[0080] Among them, the target change information refers to the data change information identified from the database operation statement; the target change information can contain the target change operation type, the target change table name, the target change field name, and the target change data type. Among them, the target change information is stored in the target change information storage table. The target change information storage table can be a table used to store the target change operation type, the target change table name, the target change field name, and the target change data type in the target change information. The target change information storage table can also store the target change script name. In this way, the target change information to be obtained can be determined by identifying the target change script name. It can be understood that the target change information storage table can also store other target change information, which is not specifically limited in this embodiment.
[0081] Among them, the target change operation type refers to the type of data operation performed on the data to be changed, which can be data addition, modification, or deletion; in the database operation statement, the corresponding database syntax for database addition is "insert", for database modification is "update", and for database deletion is "delete".
[0082] Among them, the target change table name refers to the name of the storage table where the data to be changed is located.
[0083] Among them, the target change field name refers to the name of the field corresponding to the data to be changed.
[0084] Among them, the target change data type refers to the data type of the data to be changed. Exemplarily, it can be of type long, int, or other data types. In this embodiment, no specific limitation is made.
[0085] Specifically, a database management tool can be pre-installed in the server, and then connected to the target database of the corresponding model through the database management tool. Then, the database parameter information query statement "SHOW VARIABLES" is input to query the corresponding target database information, and the queried target database information is stored in the target database information storage table. Then, the target database type is obtained from the target database information storage table, and the corresponding target change script name is matched from the target change script matching table according to the target database type. Furthermore, according to the preset storage path, the location of the target change script is determined by the local folder name, the target change script name, and the slash symbol. Finally, based on the storage path where the target change script is located, the location of the target change script can be located, and the database operation statement in the target change script can be accessed. Among them, there are multiple ways to obtain the target database information, and no specific limitation is made in this embodiment.
[0086] Step 202: Determine the target change information for data change of the data to be tested based on the target change script.
[0087] Exemplarily, the target change information can be obtained by performing lexical analysis on the database operation statement in the target change script.
[0088] Specifically, after accessing the database operation statement in the target change script based on the solution in step 201, the database operation statement can be parsed by combining a lexical analyzer and a syntax analyzer to obtain the target change operation type, the target change table name, the target change field name, and the target change data type.
[0089] Exemplarily, a lexical analyzer tool (English representation: Fast Lexical Analyzer Generator, abbreviated as FLEX) and a parser generator (English representation: Bison Parser Generator, abbreviated as BISON) can be installed in the server in the common way in advance. Among them, FLEX is mainly used to classify the vocabulary in the database statement according to the preset classification rules to realize word segmentation of the database statement. The categories of the lexicon can be divided into database operation keywords, identifiers, literals, etc. Exemplarily, the database operation keywords, identifiers, and data types can be marked as a, b, c in sequence to represent the above three types, or other symbols can also be used, which is not specifically limited in this embodiment. Specifically, the preset classification rules can be database keyword classification rules. The database keyword classification rules are mainly used to distinguish whether it is a database keyword. The database operation keywords can be stored in a keyword storage table. Database keywords refer to the fields of database operations. Exemplarily, such as "insert, from, where, update, delete", etc., or others. If there is the same keyword as that in the keyword storage table in the database operation statement, obtain the word segment and mark the word segment as a; the preset classification rules can be identifier classification rules. The identifier classification rules are mainly used to confirm whether the word segment belongs to the set name. Specifically: first query whether there is a word segment composed of characters such as letters, numbers, and underscores in the database operation statement; and then compare the word segment with each keyword in the database keyword storage table. If there is no keyword consistent with the word segment, the word segment composed of characters such as letters, numbers, and underscores belongs to the set name, obtain the word segment and mark the word segment as b; the preset classification rules can be data type classification rules, which are mainly used to confirm word segmentation of data types. The statement types in the database operation statement are stored in the data type storage table in advance. The data types are such as "int, long", etc.; then identify whether there is a data type consistent with that in the data type storage table in the database operation statement. If so, obtain the word segment and mark the word segment as c; the preset classification rules can also be set in other ways and the above-mentioned all word segment classifications can also be realized in other ways, which is not specifically limited in this embodiment.
[0090] Among them, the BION tool is a powerful parser generator. All the word segments identified according to the preset classification rules and their corresponding word segment tags can be sent to the parser generated by BISON; the parser performs syntactic analysis on these word segments with word segment tags according to the context-free grammar rules. It checks whether these word segments can be combined into legal database operation statements according to the grammar rules. During the syntactic analysis process, the parser constructs a syntax tree. The syntax tree is a tree-shaped data structure that represents the syntactic structure of the input database operation statement. Each node of the syntax tree corresponds to a syntactic category. These syntactic categories can be table names, field names, operators, data types. The corresponding information can be obtained by reading the syntactic category corresponding to the corresponding node. Exemplarily, for example, by reading the table name, the information corresponding to the table name can be extracted as the target changed table name, and then the target change operation identifier, the target changed field name, and the target change type can also be obtained in the above manner. Thus, for each input database operation statement, a piece of target change information can be obtained. Furthermore, the target change script name and its corresponding target change information can be stored in the target change information table storage table. The target change information table storage table is a table for storing change information, which can store target change information or other change information. In this embodiment, no specific limitation is made.
[0091] It can be understood that when obtaining the target change operation identifier, the target changed field name, the target changed table name, and the target change type in the target change information, if the data obtained at any one of the field positions is empty, a null value identifier can be set at the corresponding position. Among them, the null value identifier is an identifier symbol used to indicate the existence of data. Exemplarily, it can be represented as NULL for subsequent use, or it can be set in other ways. In this embodiment, no specific limitation is made.
[0092] Optionally, the database operation statement can also be input into other methods such as deep learning algorithms and traditional word segment methods for lexical analysis to obtain the target change information. In this embodiment, no specific limitation is made.
[0093] Step 203: Determine whether the target change script meets the preset test verification requirements. If it meets the preset test verification requirements, input the target change information into the database verification statement generation model trained to convergence to generate a target verification statement, where the target verification statement is used to verify whether the changed data meets the requirements of the changed data.
[0094] Among them, the preset test verification requirement is used to determine whether the target change script meets the test regulations. It can be a predefined requirement. It can be used to test the correctness and integrity of the database operation statements in the target change script and to determine whether the target change script conforms to the preset data change content, etc. Other test verification requirements can be set according to the test needs, which are not limited in this embodiment.
[0095] Among them, the target verification statement can be a database operation statement or other operation statements, which are not specifically limited in this embodiment.
[0096] Among them, the requirement for the data after change is the test requirement set for the changed data after the data change. Its purpose is to test whether the normal operations on the changed data can still be maintained after the data change. For example, it can test whether the data can be queried, modified, deleted, or read across tables, etc. Other operations on the data can also be set, which can be set according to test experience and requirements. The more comprehensive the designed test verification requirements are, the more able to ensure the operation quality of the data after the data change, which is not specifically limited in this embodiment.
[0097] When judging the target change script according to the preset test verification requirement, if the target change script meets the preset test verification requirement, it indicates that the database operation statements in the target change script are correct, complete, and conform to the preset data change content. The target change information generated in step 202 can continue to be input into the database verification statement generation model trained to convergence to generate the target verification statement. Exemplarily, assuming that the change to the data is a modification operation on the data, in order to verify that the database can still be normally operated after the data change, query statements, deletion statements, addition statements, and continued modification statements for the data can be generated, so as to verify whether the data after the change meets the requirement for the data after the change. The database verification statement generation model trained to convergence can generate the above query statements, deletion statements, addition statements, and modification statements. With different target change information, the corresponding verification requirements are also different, and thus there can be multiple situations for the generated target verification statements, and at least one target verification statement is generated. The higher the prediction accuracy of the database verification statement generation model trained to convergence, the more accurate and diverse the generated target verification statements are. Therefore, it can be verified from multiple perspectives whether the data after the change meets the requirement for the data after the change. If problems can be discovered as early as possible from a comprehensive test, the operation quality of the database can be better ensured.
[0098] Step 204: Generate a target test script based on the target database information, target change information, and target verification statement; the target test script is used to test the database to be tested after the data change.
[0099] Among them, the target test script is a script composed of multiple test statements.
[0100] Specifically, various possible test case script templates can be determined in advance according to the experience of relevant personnel for different change data tables. Among them, the test case script template, the test case template is a standardized document used to record and describe the test process, test steps, expected results, and actual results. It can include: basic information of the test, test items, test steps, etc., and can also include other information, which is not limited in this embodiment. Among them, the basic information of the test can be the target database information, which is used to access the target database information according to the address and port number of the target database in the target database information; the test item refers to the item to be tested, which can include test items for data integrity testing, performance performance testing items, compatibility testing items, concurrency testing items, and security testing items. The test items for integrity testing are used to verify whether there is data loss after data change; the performance performance testing is used to verify whether the data change affects the database performance; the compatibility testing item is used to ensure that the database can still interact normally with other application programs after the data change; the concurrency testing is used to verify the stability and response speed of the database under high concurrency, and the security testing is used to verify whether the access control mechanism of the database is effective, whether the data is encrypted and protected, and whether the audit log function can record all operations and events. It can also be other test items, which are set according to the test requirements; the test item can also include a target verification statement; it is used to execute the target verification statement to test whether the data change can continue to be operated. Finally, the corresponding test case script template can be matched according to the target change table name corresponding to the target change script; the target database information and the target verification statement are inserted into the positions of the corresponding test items in the test case script template, so as to generate the target test script for testing the database after data change.
[0101] It can be understood that the more comprehensive the test item design is, then after executing the target test script, the impact of the changed data on the database can be verified from multiple angles, so as to discover the problem of database anomalies caused by data changes as early as possible, and then ensure the quality of subsequent database applications.
[0102] It can be understood that there are various ways to design the test case script template, which are not specifically limited in this embodiment.
[0103] Optionally, such as Figure 3As shown, the target change information and target database information can be obtained in the acquisition module. The acquisition module can be used to obtain the target change script corresponding to the database to be tested, and segment the database in the target change script to obtain the target change information; and obtain the corresponding target database information based on the model of the target database. The target verification statement can also be generated in the first generation module. The first generation module can be used to input the target change information obtained in the acquisition module into the database verification statement generation model trained to convergence when the target change script meets the preset test verification requirements, so as to generate the target verification statement. The target test script can be generated in the second generation module. The second generation module can be used to determine the corresponding test case script template according to the obtained target database information, and then insert it into the test case script template according to the target database information obtained by the acquisition module to generate the target test script based on the generated target verification statement.
[0104] In this embodiment, by judging whether the target change script meets the preset test verification requirements, the accuracy of the current target change script can be determined, and then the accuracy of using the target change script for data change can be ensured. The target change information generated based on the target change script is input into the converged database verification statement generation model to generate the target verification statement. The converged database verification statement generation model can quickly generate diverse and accurate target verification statements as the target change information changes. Therefore, when generating the target test script based on the target database information, target change information, and target verification statement, the target test script also contains diverse and accurate target test statements. Finally, using the target test script to execute the test after data change on the database to be tested can improve the test efficiency and maintain the stability of the test results.
[0105] As an optional implementation manner, the preset test verification requirements include: syntax verification requirements, change information integrity verification requirements, and consistency requirements between the target change script and the preset change information. The target database information includes: target database type. The target change script contains database operation statements.
[0106] Judging whether the target change script meets the preset test verification requirements includes: executing the database operation statements according to the preset script verification scheme based on the target database type to judge whether the target change script meets the syntax verification requirements; and judging whether the target change information is complete according to the preset information integrity rule to judge whether the target change script meets the change information integrity verification requirements; and obtaining the preset change information and comparing the target change information with the preset change information to judge whether the target change script meets the consistency verification requirements. If the syntax verification requirements, change information integrity verification requirements, and consistency requirements are met at the same time, it is determined that the target change script meets the preset test verification requirements.
[0107] Among them, the syntax verification requirement is a requirement for checking whether the syntax of database operation statements in the target change script is correct.
[0108] Among them, the preset script verification scheme can be a scheme preset for verifying the syntax correctness of database operation statements. Different types of databases have different database operation statement verification commands preset, so the syntax correctness of database operation statements can be directly verified according to the database operation statement verification commands corresponding to different database types. Among them, the database operation statement verification command can be a database statement built into the database. Specifically: relevant information can be matched at the corresponding position in the database statement built into the database to obtain a database operation statement verification command that can be used. Exemplarily, the database statement verification command corresponding to the mysql database is "mysql -uusername -p dbname < script.sql", where username represents the username for logging in to the database, dbname represents the target database name, and script.sql represents the name of the target change script to be syntax-verified. Furthermore, the verification command corresponding to a mysql database operation statement can be determined by inputting the target database name, the username for logging in to the target database, and the name of the target change script into the corresponding verification command. The generation method of the database syntax verification names for other types of databases is the same as the above type, and will not be repeated in this embodiment. Then, this verification command can be stored in a python script. The database connection library built into python can be used to interact with the database. Finally, by executing the command of the predefined python script and running this python script, the syntax verification of the database operation statements in the target change script can be achieved; the above script running log result will show whether the verification script execution is successful or failed. If it returns successfully, it indicates that it meets the syntax verification requirements; if it returns failed, it indicates that it does not meet the syntax verification requirements. Among them, python is a scripting language that combines interpretability, compilation, interactivity, and object orientation. The python script execution command refers to the command for executing the python script, and the python script execution command can be generated by inputting python and the name of the python script. Among them, the preset script verification scheme can have multiple setting methods, which are not specifically limited in this embodiment.
[0109] Among them, the preset information integrity verification requirement is a requirement for verifying whether the target change information included in the database operation statements in the target change script is complete, and it is preset.
[0110] Specifically, it is possible to access whether there is a null value flag at the corresponding positions of the target change operation type, target change table name, target change field name, and target change data type in the target change information storage table. If it is detected that there is a null value flag, it indicates that there is a vacancy in the corresponding position of the table for the target change information, which means that it does not meet the requirements of the preset information integrity verification. When it is detected that one of the values of the target change operation type, target change table name, target change field name, and target change data type in the target change information storage table is NULL, it indicates that it does not meet the requirements of the preset information integrity verification. The method for judging the requirements of the preset information integrity verification can also be other methods, which are not specifically limited in this embodiment.
[0111] Among them, the preset change information refers to the information for presetting data changes to the database to be tested; the preset change information may include: the target change script name associated and matched with the preset change information, the preset change operation type, the preset change table name, the preset change field name, and the preset change data type. The preset change information can be stored in the expected change information storage table, which is a table storing the preset change operation type, preset change table name, preset change field name, and preset change data type in the preset change information. The preset change information storage table can also store the target change script name corresponding to the preset change information. It can be understood that the preset change information storage table can also store other preset change information, which is not specifically limited in this embodiment.
[0112] Among them, the target change script name associated and matched with the preset change information refers to the name of the target change script corresponding to the target change information compared with the preset change information.
[0113] Among them, the preset change operation type refers to the set type of data change operation, which can be data addition, modification, or deletion; in the database operation statement, the corresponding database syntax for database addition is "insert", the database modification corresponds to "update", and the database deletion corresponds to "delete".
[0114] Among them, the preset change table name refers to the name of the storage table where the changed data is located according to the change requirements.
[0115] Among them, the preset table change field name refers to the name of the field corresponding to the data to be changed.
[0116] Among them, the preset change data type refers to the type of the data to be changed.
[0117] Understandably, the preset change information can be set by relevant personnel according to the change requirements, which represents the actual data change requirements of the relevant personnel. Therefore, as long as the target change information is compared with the preset change information, it can be determined whether the target change script can meet the actual data change requirements of the personnel related to the test.
[0118] Specifically, the python script execution command can be obtained and executed in the above manner to check whether the target change script meets the syntax verification requirements. If the python script execution command returns a success identifier, it indicates that the target change script meets the syntax verification requirements; if the python script execution command returns a failure identifier, it indicates that the target change script does not meet the syntax verification requirements. Here, the success identifier is a symbol representing a successful return result; the failure identifier is a symbol representing a failure result. Exemplarily, the success identifier can be represented by "success"; the failure identifier can be represented by "failed", or other symbols can be used to represent the success identifier and the failure identifier, which are not specifically limited in this embodiment. All the success identifiers and failure identifiers proposed in this application are consistent with the above success identifier and failure representation symbols, and will not be repeated hereinafter.
[0119] After the target change script meets the syntax verification requirements, it can continue to verify whether the target change script meets the change information integrity verification requirements. The specific verification method is as described above for the preset information integrity verification requirements, which will not be repeated in this embodiment.
[0120] After verifying that the target change script meets the change information integrity verification requirements, it can be verified whether the target change script meets the consistency requirement between the target change script and the preset change information. Specifically: the corresponding target change information can be matched in the target change information storage table according to the target change script name, and then the target change script name associated with the preset change information with the same target change script name can be searched in the preset change information storage table, so as to obtain the preset change corresponding to the target change script name associated with the preset change information. Finally, the target change operation type in the target change information is compared with the preset change operation type in the preset change information; the target change table name in the target change information is compared with the preset change table name in the preset change information, the target change field name in the target change information is compared with the preset change field name in the preset change information, and the target change data type in the target change information is compared with the preset change data type in the preset change information. When there are no differences in all comparison results, it indicates that the target change script meets the consistency requirement between the target change script and the preset change information; otherwise, it does not meet the above consistency requirement.
[0121] Understandably, the order and manner of the above verification grammar verification requirements, change information integrity verification requirements, and target change script and preset change information consistency requirements are only illustrative examples, and none of them are unique. The verification order and verification method can be set arbitrarily according to requirements, and no specific limitation is made in this embodiment.
[0122] Understandably, only when the above grammar verification requirements, change information integrity verification requirements, and target change script and preset change information consistency requirements are all met, it indicates that the target change script meets the preset test verification requirements. If any one of them is not met, the test will be exited; and the tester or other staff will be reported which specific requirement is not met. After the tester or other staff corrects the target change script, the test task will be executed again.
[0123] In this embodiment, by verifying the grammar verification requirements, it can be ensured that the target change script can be executed correctly; by verifying the change information integrity verification requirements, it can be ensured that the target change information in the target change script is complete, avoiding omission of the target change information; by the target change script and preset change information consistency requirements, it can be ensured that the task of actually performing data changes is consistent with the change task to be achieved, and to ensure that other data is not modified by mistake; thus, executing the target change script that is correct and in line with the change requirements can improve the efficiency of the test process and avoid test failures caused by executing the target change script.
[0124] As an optional implementation manner, generating a target test script based on the target change information and the target verification statement includes: obtaining a test scenario that matches the target change information; obtaining a test case script template that matches the test scenario; the test case script template includes configuration items; adding the target verification statement to the configuration items of the test case script template to generate a target test script.
[0125] Among them, the test scenario that matches the target change information refers to a test scenario set for different target change information, which is analyzed and set by relevant personnel according to existing test methods and test experience for different target change information; among them, there are various ways to set the test scenario, and no specific limitation is made in this embodiment.
[0126] Understandably, in order to optimize the test process and improve test efficiency, test scenario partitioning can be performed in advance, and then test case script templates can be designed according to the test scenarios. Optionally, the same type of data change operation can be classified into the same change situation, and test scenarios can be designed accordingly. Thus, test case scripts can be designed for the test scenarios, and the names of the test case scripts can be named after the names of the test scenarios. Then, the designed test scenario names and the types of data change operations are associated and matched in the test scenario matching table. Among them, the test scenario matching table is a table used to store test scenario names and their corresponding test scenario categories.
[0127] Optionally, classification can also be performed according to the actual use of the target change table name or change field name, and then test scenarios can be partitioned and test case script templates can be designed according to the test scenarios. Other ways of partitioning test scenarios are also possible, and no specific limitations are imposed in this embodiment.
[0128] Exemplarily, taking the Jmeter script template as an example, where Jmeter is a test tool whose working principle is to submit requests to the server and obtain the results returned by the requests from the server. The performance and stability of the target database test can be evaluated by simulating multi-user concurrent access to the target database, sending network protocol requests simultaneously, and measuring response time, throughput, number of concurrent users, error rate, and performance metrics, etc. The Jmeter script template can contain configuration items, which can include: thread group configuration items, configuration element configuration items, sampler configuration items, assertion configuration items, listener configuration items, logic controller configuration items, and other configuration items can also be included. The above configuration items all belong to the prior art, and their specific meanings will not be elaborated in detail. Among them, the thread group configuration item can be used to set the number of test users to be simulated, the time interval between each user's runs: the number of times the test needs to be looped for each user's test, and a fixed number or infinite loop can be selected. The configuration element configuration item is used to set the target change database information, target verification statements, etc. Its role is to provide necessary configuration information or data for subsequent samplers and other components; therefore, the username for logging in to the target database, the password for logging in to the target database, the address of the target database, and the target verification statement or other test parameters need to be configured in the configuration element configuration item; the sampler is a component used to send requests to the server, and the address of the target database and the port number of the target database need to be set in the sampler; the assertion is used to determine whether the test results after executing the target change script meet the expectations, and can be presented in the form of a success identifier or a failure identifier; the listener is used to collect the test results after executing the target change script, and can be presented in the form of a test report; the logic controller is used to control the process of the test after executing the target change script. The above configuration items can all be set according to the test requirements or tests themselves, and no specific limitations are imposed in this embodiment.
[0129] Understandably, the above JMeter script template configuration method is only for illustrative purposes and is not the only way to generate a test case script template. Test case script templates can also be generated based on other test frameworks, which are not specifically limited in this embodiment.
[0130] Understandably, in the JMeter script template, the thread group configuration items, assertion configuration items, and listener configuration items do not need to be repeatedly configured. Therefore, these configuration items can be set in a fixed form as long as they meet the test requirements; the content filled in the configuration element configuration items and sampler configuration items of the JMeter script template changes; therefore, it is necessary to configure the target database information and target verification statements in the configuration element configuration items and sampler configuration items of the JMeter script template to obtain the target test script.
[0131] Specifically, the target change operation identifier can be obtained from the target change information storage table, and then the corresponding test scenario name can be matched from the test scenario matching table according to the target change table name and the target change operation identifier; according to the test scenario name and the preset test case script template storage directory, and according to the preset path generation method, the path where the test case template is located can be determined; the test case template can be located according to the accessed test case template path, and the content in the test case template can be read; then, the user name for logging in to the target database, the password for logging in to the target database, the address of the target database, and the port number of the target database can be obtained by reading the target database information storage table; then, according to the user name field in the configuration item, the user name for logging in to the target database can be identified and filled into the filling position of the user name; according to the password field in the configuration item, the password for logging in to the target database can be matched and filled into the filling position of the password; according to the address field in the configuration item, the address of the target database can be matched and filled into the filling position of the address; according to the address field in the sampler, the address of the target database can be matched and filled into the filling position of the address; according to the port number field in the sampler, the port number of the target database can be identified and filled into the filling position of the port number; the target verification statement obtained in step 202 can be directly inserted into the test content filling position in the configuration item; in this way, the target test script can be obtained; executing this test script can complete the test after executing the target change script and generate a test report, and the corresponding test results can be viewed from the test report; and problems after executing the target change script can be discovered in time and improved in time. Among them, the preset test case template path is generated in the same way as the storage path where the target change script is located, and will not be repeated here.
[0132] In this embodiment, the corresponding test scenarios are directly matched through the target change information, and the test case scripts are quickly located according to the test scenarios; then the obtained target database information and target verification statements are directly added to the configuration items of the test case script template. This process does not require any manual intervention and realizes the rapid generation of the target test script through an automated matching method.
[0133] As an alternative implementation, the database verification statement generation model is a neural network model; the training steps of the database verification statement generation model trained to convergence include: obtaining historical change information; the historical change information includes a historical change operation identifier, a historical change data table name, a historical change field name, and a historical change data type; matching the corresponding historical change verification identifier based on the historical change operation identifier; generating a historical verification statement based on the historical change information and the historical verification identifier; there is at least one historical verification statement; using the historical change data table name, the historical change field name, the historical change operation identifier, and the historical change data type as data change features; using the historical verification statement as the label of the training sample; using the data change features and their corresponding training sample labels as training sample data; inputting the training sample data into the initial neural network model for training until the initial neural network model is trained to convergence to obtain the database verification statement generation model trained to convergence.
[0134] Among them, the historical change information refers to the information of data changes in the past period of time. It can be the historical change information generated by lexical analysis of the database in the historical change script after executing the historical change script in the past period of time. The historical change information can be stored in the historical change information storage table, and the historical change information storage table can also store the historical change script name; historical change information can also be obtained by other means, which is not specifically limited in this embodiment.
[0135] Among them, the historical change operation identifier is a marking symbol for data change operations in the past period of time, which can be data addition, change, or deletion; in the database operation statement, the corresponding database syntax for database addition is "insert", the database modification corresponds to "update", and the database deletion corresponds to "delete".
[0136] Among them, the historical change data table name is the name of the table for the changed data in the past period of time.
[0137] Among them, the historical change field name refers to the name of the changed field in the past period of time.
[0138] Among them, the historical change data type refers to the type of the changed data in the past period of time, which is the same as the data types included in the target change data type.
[0139] Among them, the historical change verification identifier is an identifier used for verification after historical change operations. It is generated based on the historical change operation identifier. Exemplarily, it can be preset that if the historical change verification identifier is an addition identifier or a modification, the historical change verification identifier can be deletion, addition, modification, or query; if the historical change operation identifier is deletion, the historical change verification identifier can be query or addition; it can also be other preset methods, which are not specifically limited in this embodiment. The historical change verification identifier and its corresponding historical change verification identifier can be stored in the historical change verification identifier storage table.
[0140] Among them, the historical verification statement: is a database operation statement used to verify whether the test requirements are met after historical change operations. The historical verification statement is generated by inserting the target change information into the database statement template corresponding to the historical change verification identifier. The database statement template refers to the database statement set according to the database operation type, and the historical change verification identifier can correspond to a database statement template. Exemplarily, if the historical change verification identifier is a deletion identifier, the corresponding database statement template is "ALTER TABLE table name DROP COLUMN field name". In the prior art, there are corresponding database template statements for addition identifiers, modification identifiers, query identifiers, etc., which are not elaborated in detail in this embodiment; the historical verification statements for data addition, modification, query, or other operations are obtained in the above manner, which are not elaborated in detail in this embodiment. There are various ways to generate historical verification statements, which are not specifically limited in this embodiment.
[0141] Specifically, the historical change information can be sequentially obtained from the historical change information storage table, and then the historical change operation identifier consistent with it can be matched in the historical change verification identifier storage table according to the historical change identifier in the historical change information, and the historical change verification identifier associated with the position corresponding to the historical change operation identifier can be obtained; then the corresponding database statement template can be matched according to the historical change verification identifier; the historical change data table name and historical change field name in the target change information are filled into the database statement template according to the database operation statement syntax to generate the historical verification statement until all the historical verification statements corresponding to the historical change identifiers in all the historical change information are obtained. Each historical change identifier corresponds to at least one historical verification statement.
[0142] Among them, the neural network model can be a sequence-to-sequence neural network model or other neural network models, which are not specifically limited in this embodiment.
[0143] After obtaining the historical verification statements, the historical change data table name, historical change field name, historical change operation identifier, and historical change data type in each piece of historical change information in the historical change information storage table can be used as data change features; the historical verification statement corresponding to each piece of historical change information can be used as the label of the training sample; then each data change feature and the label of the training sample are combined into a sample for training; all the training samples can be divided into a training set and a test set according to a ratio of 8:2; among them, the training set is used to train the neural network model; the test set is used to test the accuracy of the neural network model. Then, the training set is input into the constructed neural network model for iterative training; the test set will be synchronously input into the iterated neural network model and the accuracy rate of the model test will be generated. When the accuracy rate of the model test is greater than the preset model test accuracy rate threshold, it can be considered that the model has converged. In this way, the neural network model trained to convergence is used as the database verification statement generation model trained to convergence. Among them, the model test accuracy rate threshold can be set to 95%, 98%, and can be set according to requirements, and is not limited in this embodiment.
[0144] In this embodiment, the target verification data can be accurately generated according to the obtained historical change information and historical verification identifier, providing accurate training sample labels for the neural network model; using the historical change data table name, historical change field name, historical change operation identifier, and historical change data type as data change features enriches the sample data; the neural network model has a fast prediction speed, strong learning ability and feature extraction ability. Therefore, more historical change information can be learned during the training process of inputting the training sample data into the initial neural network model, and then a database verification statement generation model trained to convergence with high accuracy can be trained; furthermore, through the database verification statement generation model trained to convergence, accurate target test scripts can be quickly predicted.
[0145] As an optional implementation manner, it further includes: in response to the successful execution of the target test script, storing the target change information and its corresponding target verification statement; obtaining the stored target change information and its corresponding target verification statement, and updating the training sample data based on the target change information and its corresponding target verification statement; optimizing the database verification statement generation model trained to convergence based on the updated sample data.
[0146] Specifically, if the target test script is successful, it indicates that the test is successful. Then, the target change operation type, target change table name, target change field name, target change data type, and their corresponding target verification statements in the target change information can be stored in the target verification statement storage table, and a sample update identifier is added to each piece of target change information. The sample update identifier is a symbol used to indicate whether the sample data has been updated and can be marked as 0 or 1. 0 indicates that it has been updated, and 1 indicates that it has not been updated. It can also be represented by other symbols, which are not limited in this embodiment.
[0147] Specifically, the symbols with a sample update identifier of 1 in the target verification statement storage table can be queried, and the target change script names corresponding to the symbols with a sample update identifier of 1 can be obtained respectively. Then, the target change script name is compared with the historical change scripts in the historical change information storage table to check if there are the same script names. If there are different script names, it means that the target change script has not been executed in the past. Then, all the target change information corresponding to the unexecuted target change script and its corresponding target verification statements can be directly used to expand the training sample data to generate new training samples. If there are the same script names, the target change operation type, target change table name, target change field name, and target change data type in the target change information corresponding to the target change script can be compared one by one with the historical change operation identifier, historical change data table name, historical change field name, and historical change data type corresponding to the same script name in the historical change information storage table. If there is a different comparison result, it means that the database operation statements in the target change script have not been executed. Then, this piece of target change information and its corresponding target verification statements can be expanded into the training sample data to generate new training samples.
[0148] Then, the new training sample data can be continuously divided into a training set and a test set in a ratio of 8:2. Then, the training set is input into the constructed neural network model for iterative training. The test set will be synchronously input into the iterated neural network model and the accuracy of the model test will be generated. When the accuracy of the model test is greater than the preset model test accuracy threshold, it can be considered that the model has converged, and the neural network model trained to convergence is used as the newly trained database verification statement generation model. In this way, the database verification statement generation model trained to convergence is optimized based on the updated sample data. Among them, the model test accuracy threshold can be set to 95% or 98%, which can be set according to requirements and is not limited in this embodiment.
[0149] In this embodiment, in response to the successful execution of the target test script, the target change information and its corresponding target verification statement are stored; the stored target change information and its corresponding target verification statement are obtained, and the training sample data is updated based on the target change information and its corresponding target verification statement; the database verification statement generation model trained to convergence is optimized based on the updated sample data; updating the training sample data can enrich the sample data and maintain the accuracy of the sample data. Furthermore, the updated sample data is used to optimize the database verification statement generation model trained to convergence, so as to improve the prediction accuracy of the database verification statement generation model trained to convergence, and thus a more correct target test script can be obtained to better meet the test requirements after the execution of the target change script.
[0150] As an optional implementation, a target rollback script is generated based on the target change information; if the execution of the target change script fails, the test is exited and the changed data is rolled back according to the target rollback script; if the execution of the target change script is successful, the target test script is executed and a test report is generated; if the test report shows that the execution of the target test script fails, the changed data is rolled back according to the target rollback script.
[0151] Among them, the target rollback script refers to the script for rolling back the changed data; the target rollback script is generated according to the target change information and can also include database operation statements. The database operation statements in the target rollback script contain target rollback information, and the target rollback information includes the target rollback operation type, the target rollback table name, the target rollback data, the target rollback field name, and the target rollback data type.
[0152] Among them, the target rollback information refers to the operation and data information for rolling back the changed data, and it can be stored in the target rollback information storage table.
[0153] Among them, the target rollback operation type refers to the type of data rollback performed on more data, which can be data addition, modification, or deletion; the target rollback operation type is matched according to the target change operation type. Exemplarily, if the target change operation type is found to be addition, the target rollback operation type is matched to deletion; if the target change operation type is found to be modification, the target rollback operation type is also matched to modification; if the target change operation type is found to be deletion, the target rollback operation type is matched to addition. The target rollback operation types matched with each target change operation type can be associated and stored in the database operation type matching table according to the above matching rules. The database operation type matching table is a table used to store the target change operation type and the target rollback operation type. Among them, the target change operation type and the target rollback operation type can be associated and matched according to the above fields; other data can also be stored, which is not specifically limited in this embodiment. It can also be other operation type matching methods, which are not specifically limited in this embodiment.
[0154] Among them, the target rollback table name refers to the name of the storage table where the data to be rollbacked is located, which is the same as the target change table name.
[0155] Among them, the target rollback data refers to the data before the data change. Before the target change script performs the data change operation, a data query statement can be set; and the directly queried target rollback data is stored in the target rollback information storage table; among them, when there are more than two pieces of target rollback data, the target change script name, the target change field name, the target change table name, and the target rollback data are backed up to the data backup table. The data backup table is a table used to store backup data. The naming method of the data backup table name is the combination of the target change script name and the target change table name. Therefore, the corresponding data backup table can be found through the target change script name and the target change table name; the data backup table can be used to store the target rollback data, and other data can also be stored, which is not specifically limited in this embodiment. When there are more than two pieces of target rollback data, a data backup table identifier can be set at the corresponding position of the target rollback data in the target rollback information storage table. When the data backup table identifier is accessed at the corresponding position of the target rollback data, the data backup table is directly accessed to obtain the target rollback data. Among them, the data backup table identifier is a preset symbol used to identify that it is necessary to access the backup data table to obtain the target rollback data. It can be set to "get", or other symbols, which are not specifically limited in this embodiment.
[0156] Among them, the target rollback field name refers to the name of the field corresponding to the data to be rollbacked, which is the same as the target change field name.
[0157] Among them, the target rollback data type refers to the type of data to be rolled back, which is the same as the data type before the data change. Exemplarily, the data type before the data change can be obtained in the following way. Before performing the data change operation on the target change script, a data type query statement can be set to query the target rollback type and store it in the rollback data type storage table. In order to obtain the corresponding target rollback type and add a unique type index to the target rollback type; among them, the type index is an index used to find the data type; it is unique. The target change script, target change field, target change table name, and target change operation can be concatenated into a field as a type index; or the type index can be obtained by other means, which is not limited in this embodiment. Among them, the rollback data type storage table is a table used to store data types and can also store other types of data; each time a test is executed, this table needs to be cleared to facilitate the search for data types and save space; there are multiple ways to obtain the data type, which is not specifically limited in this embodiment.
[0158] Specifically, the current target change information can be matched from the target change information storage table according to the target change script name, and the target change operation type in the target change information is matched with the target change type stored in the database operation type matching table. When a consistent target change type is matched, the associated stored target rollback operation can be used as the target rollback operation corresponding to the current target change information. Then, the target change table name in the current target change information is used as the target rollback table name; the target change field name in the current target change information is used as the target rollback field name; finally, the target rollback data is obtained from the historical change information storage table. If it is recognized that the corresponding position of the target rollback data is "get", it indicates that there are multiple current target change data, then the backup data table name with the same combination field as the target change script name and the target change table name is searched, and the data in this backup data table is used as the target rollback data. The data type before the data change obtained in advance; the target change script, target change field, target change table name, and target change operation in the target change information are concatenated into a field, and then the same field is matched in the rollback data type storage table, and the type corresponding to this same field is used as the target rollback type. Thus, according to the above-obtained target rollback operation, target rollback table name, target rollback data, target rollback type, and target rollback field, and filling the above information into the corresponding database operation statement position according to the database syntax, database operation statements for data rollback are generated. For each target change information, the same number of database operation statements for data rollback are generated and stored in the target rollback script.
[0159] When the target change script fails to execute, it indicates that there may be some database operation statements in the target change script that have not been successfully executed; the changed data needs to be rolled back. First, to facilitate the identification of successfully executed database operation statements, after executing a database operation statement and returning a success identifier, a data change result identifier can be recorded step by step in the target change information storage table; among them, the data change result identifier is an identifier symbol used to represent the execution result of a database operation statement, which can be represented as 0 or 1, 2, where 0 indicates execution failure, 1 indicates execution success, and 2 indicates processed; when starting a new test, all data change result identifiers need to be set to 2; it can also be represented by other symbols, which are not specifically limited in this embodiment. Then, the number of target change script names in the target change script execution record that are the same as the current target change script name and the data change result identifier is 1 can be counted, and this number is used as the number of statements executed by the database operation statement.
[0160] It can be implemented by software code to sequentially execute a fixed number of database operation statements; to roll back the changed data.
[0161] When the target change script executes successfully, it indicates that all database operation statements in the target change script have been successfully executed and the corresponding data changes have been completed; the target test script can continue to be run on the server according to the test script execution command, and a test report can be generated. The test report can include: test title, test environment, test execution status, and test results, etc. Exemplarily, the test results are represented by "success" and "failed"; among them, "success" indicates success and "failed" indicates failure. Furthermore, when it is queried that the test result is "failed", it indicates that the test result is a failure, and the target rollback script can be run according to the target rollback script execution command to roll back all the changed data for subsequent continuous testing. Among them, the test script execution command needs to be determined according to different codes, which belongs to the prior art and will not be elaborated in detail in this embodiment.
[0162] In this embodiment, a target rollback script is generated based on the target change information; if the target change script fails to execute, the test is exited and the changed data is rolled back according to the target rollback script; if the target change script executes successfully, the target test script is executed and a test report is generated; if the test report shows that the target test script fails to execute, the changed data is rolled back according to the target rollback script; a more accurate target rollback script can be generated based on comprehensive target change information. Furthermore, when the target change script fails to execute or the target test script fails to execute, the target rollback script can be used to quickly and accurately restore the changed data.
[0163] Figure 4The flowchart of the test case generation method provided by an embodiment of this application is as follows. As Figure 4 shown, it shows the test case generation process, specifically: obtaining the target database information and the target change script corresponding to the database to be tested, and then determining the target change information for changing the data to be tested based on the target change script; then judging whether the target change script meets the preset test verification requirements. If it does not meet the requirements, directly exit the test; if it meets the preset test verification requirements, input the target change information into the database verification statement generation model trained to convergence to generate the target verification statement; thus, it is possible to generate the target test script based on the target database information, the target change information, and the target verification statement; after generating the target test script, first generate the target rollback script based on the target change information and back up the data before the change; then execute the target change script. If the execution of the target change script fails, exit the test and execute the target rollback script to synchronize the backup data to the position corresponding to the changed data to implement the rollback of the changed data; if the execution of the target change script is successful, continue to execute the target test script; during the execution of the target test script, synchronously record the test process and generate a test report; if the test report returns a test failure, continue to execute the target rollback script to synchronize the backup data to the position corresponding to the rollback changed data to implement the rollback of the changed data.
[0164] The implementation manner and technical effect in this embodiment are similar to those of the corresponding solution in the above embodiment, and will not be elaborated here.
[0165] The test case generation device provided by this embodiment can execute the method provided by the above method embodiment, and its implementation principle and technical effect are similar, and will not be elaborated here in this embodiment.
[0166] Figure 5 The schematic diagram of the test case generation device provided by an embodiment of this application. As Figure 5 shown, the test case generation device provided by this embodiment is located in the test case generation device. Then the data synchronization device 50 provided by this embodiment includes: an acquisition module 501, a determination module 502, a first generation module 503, and a second generation module 504.
[0167] The acquisition module 501 is used to acquire the target database information and the target change script corresponding to the database to be tested; the target change script is a script for executing data changes in the database to be tested;
[0168] The determination module 502 is used to determine the target change information for changing the data to be tested based on the target change script;
[0169] The first generation module 503 is configured to determine whether the target change script meets the preset test verification requirements. If the preset test verification requirements are met, the target change information is input into the database verification statement generation model trained to convergence to generate a target verification statement, which is used to verify whether the data after the change meets the requirements of the data after the change;
[0170] The second generation module 504 is configured to generate a target test script based on the target database information, the target change information, and the target verification statement; the target test script is used to test the database to be tested after the data change.
[0171] Optionally, the preset test verification requirements include: syntax verification requirements, change information integrity verification requirements, and consistency requirements between the target change script and the preset change information of the change requirements.
[0172] Correspondingly, when determining whether the target change script meets the preset test verification requirements, the determination module 502 is specifically configured to:
[0173] Execute database operation statements according to the preset script verification scheme based on the target database type to determine whether the target change script meets the syntax verification requirements; and, determine whether the target change information is complete according to the preset information integrity rule to determine whether the target change script meets the change information integrity verification requirements; and, obtain the preset change information, and compare the target change information with the preset change information to determine whether the target change script meets the consistency verification requirements; if the syntax verification requirements, the change information integrity verification requirements, and the consistency requirements are met at the same time, it is determined that the target change script meets the preset test verification requirements.
[0174] Optionally, when generating the target test script based on the target database information, the target change information, and the target verification statement, the first generation module 503 is specifically configured to:
[0175] Obtain a test scenario that matches the target change information; obtain a test case script template that matches the test scenario; the test case script template includes configuration items; add the target database information and the target verification statement to the configuration items of the test case script template to generate a target test script.
[0176] Optionally, the database verification statement generation model is a neural network model.
[0177] Correspondingly, the test case generation device may further include a training module.
[0178] Optionally, when the database verification statement generation model is a neural network model, the training module is specifically configured to:
[0179] For obtaining historical change information; the historical change information includes a historical change operation identifier, a historical change data table name, a historical change field name, a historical change data type, and a historical database operation statement; matching a corresponding historical change verification identifier based on the historical change operation identifier; generating a historical verification statement based on the historical change information and the historical verification identifier; the historical verification statement is at least one; using the historical change data table name, the historical change field name, the historical change operation identifier, and the historical change data type as data change features; using the historical verification statement as the label of the training sample; using the data change features and the labels of their corresponding training samples as training sample data; inputting the training sample data into an initial neural network model for training until the initial neural network model is trained to convergence to obtain a database verification statement generation model trained to convergence.
[0180] Optionally, the training module is further configured to: in response to successful execution of the target test script, store the target change information and its corresponding target verification statement; obtain the stored target change information and its corresponding target verification statement, and update the training sample data based on the target change information and its corresponding target verification statement; optimize the database verification statement generation model trained to convergence based on the updated sample data.
[0181] Optionally, the test case generation device may further include: a rollback module.
[0182] Correspondingly, the rollback module is specifically configured to: generate a target rollback script based on the target change information; if the target change script fails to execute, exit the test and roll back the changed data according to the target rollback script; if the target change script is successfully executed, execute the target test script and generate a test report; if the test report shows that the target test script fails to execute, roll back the changed data according to the target rollback script.
[0183] Figure 6 This is a schematic structural diagram of the electronic device provided in the embodiments of the present application. As Figure 6 shown, the electronic device 60 provided in this embodiment includes: at least one processor 601 and a memory 602. Optionally, the device 60 further includes a communication component. Among them, the processor 601, the memory 602, and the communication component are connected through a bus.
[0184] In a specific implementation process, at least one processor 601 executes the computer execution instructions stored in the memory 602, so that at least one processor 601 executes the above method.
[0185] The specific implementation process of the processor 601 can refer to the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here in this embodiment.
[0186] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU for short), or other general-purpose processors, digital signal processors (DSP for short), application specific integrated circuits (ASIC for short), etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in combination with the invention can be directly implemented by the execution of the hardware processor, or by the combination of hardware and software modules in the processor.
[0187] The memory may include a high-speed random access memory (RAM), and may also include non-volatile memory (NVM), such as at least one disk memory.
[0188] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, the bus in the drawings of this application is not limited to only one bus or one type of bus.
[0189] This application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0190] This application also provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the processor executes the computer-executable instructions, the above method is implemented.
[0191] The above-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk or an optical disc. The readable storage medium can be any available medium accessible by a general-purpose or special-purpose computer.
[0192] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be part of the processor. The processor and the readable storage medium can be located in an Application Specific Integrated Circuits (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in a device.
[0193] The division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Additionally, the couplings or direct couplings or communication connections shown or discussed among each other can be indirect couplings or communication connections through some interfaces, devices or units, and can be in electrical, mechanical or other forms.
[0194] The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0195] In addition, in each embodiment of the present invention, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0196] If the function is implemented in the form of 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 the present invention, in essence, or the part that contributes to the prior art or a part of this technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks or optical discs that can store program codes.
[0197] Those of ordinary skill in the art will understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments; and the aforementioned storage medium includes: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0198] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses, or adaptations of the present invention, which follow the general principles of the present invention and include known common knowledge or conventional technical means in the technical field not disclosed in the present invention. It is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present invention is only limited by the appended claims.
Claims
1. A test case generation method, characterized in that Including: Obtain the target database information and the target change script corresponding to the database to be tested; The target change script is a script for performing data changes in the database to be tested; Determine the target change information for changing the data to be tested based on the target change script; Judge whether the target change script meets the preset test verification requirements. If it meets the preset test verification requirements, input the target change information into the database verification statement generation model trained to convergence to generate a target verification statement, and the target verification statement is used to verify whether the changed data meets the requirements of the changed data; Generate a target test script based on the target database information, the target change information, and the target verification statement; The target test script is used to test the database to be tested after data change.
2. The method according to claim 1, characterized in that The preset test verification requirements include: syntax verification requirements, change information integrity verification requirements, and consistency requirements between the target change script and the preset change information; the target database information includes: target database type; the target change script contains database operation statements; The judgment of whether the target change script meets the preset test verification requirements includes: Execute the database operation statements according to the preset script verification scheme based on the target database type to judge whether the target change script meets the syntax verification requirements; Moreover, judge whether the target change information is complete according to the preset information integrity rule to judge whether the target change script meets the change information integrity verification requirements; Moreover, obtain the preset change information and compare the target change information with the preset change information to judge whether the target change script meets the consistency verification requirements; If it meets the syntax verification requirements, the change information integrity verification requirements, and the consistency requirements at the same time, it is determined that the target change script meets the preset test verification requirements.
3. The method according to claim 1, wherein The generation of the target test script based on the target database information, the target change information, and the target verification statement includes: Obtain the test scenario matching the target change information; Obtain the test case script template matching the test scenario; the test case script template includes configuration items; Add the target database information and the target verification statement to the configuration items of the test case script template to generate a target test script.
4. The method according to any one of claims 1 to 3, characterized in that, The database verification statement generation model is a neural network model; the training steps of the database verification statement generation model trained to convergence include: Obtain historical change information; the historical change information includes historical change operation identifiers, historical change data table names, historical change field names, and historical change data types; Match the corresponding historical change verification identifier based on the historical change operation identifier; Generate historical verification statements based on the historical change information and the historical verification identifier; there is at least one historical verification statement; Use the historical change data table name, the historical change field name, the historical change operation identifier, and the historical change data type as data change features; use the historical verification statement as the label of the training sample; Use the data change feature and the label of its corresponding training sample as training sample data; Input the training sample data into the initial neural network model for training until the initial neural network model converges, so as to obtain a database verification statement generation model trained to convergence.
5. The method according to claim 4, wherein It further includes: In response to the successful execution of the target test script, store the target change information and its corresponding target verification statement; Obtain the stored target change information and its corresponding target verification statement, and update the training sample data based on the target change information and its corresponding target verification statement; Optimize the database verification statement generation model trained to convergence based on the updated sample data.
6. The method according to claim 1, characterized in that, The method further includes: Generate a target rollback script based on the target change information; If the execution of the target change script fails, exit the test and roll back the changed data according to the target rollback script; If the execution of the target change script is successful, execute the target test script and generate a test report; If the test report shows that the execution of the target test script fails, roll back the changed data according to the target rollback script.
7. A test case generation device, characterized in that It includes: An acquisition module for acquiring the target database information and the target change script corresponding to the database to be tested; The target change script is a script for executing data changes in the database to be tested; A determination module for determining the target change information for data changes to the data to be tested based on the target change script; A first generation module for determining whether the target change script meets the preset test verification requirements. If it meets the preset test verification requirements, input the target change information into the database verification statement generation model trained to convergence to generate a target verification statement, where the target verification statement is used to verify whether the changed data meets the requirements of the changed data; A second generation module for generating a target test script based on the target database information, the target change information, and the target verification statement; The target test script is used to test the database to be tested after data changes.
8. An electronic device, characterized in that, It includes: A memory, a processor; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, so that the processor executes the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer execution instructions, and when the computer execution instructions are executed by the processor, they are used to implement the method according to any one of claims 1-6.
10. A computer program product, characterized in that, It includes a computer program, and when the computer program is executed by the processor, it implements the method according to any one of claims 1-6.