Drive case generation method and device and electronic equipment
By analyzing the syntactic features and mapping rules of SQL statements, the target interface template is automatically determined from the candidate template list, solving the problems of time-consuming and error-prone manual coding, and realizing efficient generation and adaptability of driving test cases.
Patent Information
- Application Number
- CN202511084889.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-04
- Publication Date
- 2025-11-21
AI Technical Summary
Existing methods for generating driver test cases rely on manual coding, which is time-consuming and error-prone, especially for inexperienced developers, making it difficult to generate driver test cases that meet different application scenarios.
By obtaining reference files and driver types, analyzing the syntax features of SQL statements, using mapping rules to determine the target interface template from the candidate template list, and injecting the SQL statement into the target interface template, driver test cases are automatically generated.
It enables automated generation of driving test cases, improves the generation speed, avoids errors caused by manual coding, and adapts to the needs of different application scenarios.
Smart Images

Figure CN120994170A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, and particularly relates to a driving use case generation method and device and electronic equipment. BACKGROUND
[0002] With the development of big data technology, the application of SQL statements is more and more widespread. In the process of database application and development, developers use SQL statements as the core instruction for operating databases, interact with databases through SQL statements, and complete corresponding operations.
[0003] However, different application scenarios have different requirements for the execution of SQL statements. In order to ensure that the SQL statements can be normally executed in the corresponding application scenarios, specific driving use cases need to be generated.
[0004] In the related art, the existing driving use case generation method mainly relies on manual coding, that is, the developer manually writes the corresponding driving use case line by line and statement by statement according to the SQL file and the application scenario. This requires very high code ability of the developer, and it is a great challenge for personnel who only master the basic SQL and lack driving development experience. At the same time, when the SQL file contains a large number of SQL statements that need to be processed, the number of driving use cases that need to be manually written is large, the whole process is time-consuming, and manual coding is prone to errors such as interface call errors and resource release omissions, which leads to errors in driving use case writing. SUMMARY
[0005] The purpose of the embodiments of the present application is to provide a driving use case generation method, device and electronic equipment to automatically generate driving use cases. The specific technical solutions are as follows:
[0006] In a first aspect of the embodiments of the present application, a driving use case generation method is provided, which comprises:
[0007] obtaining a reference file and a driving type, and obtaining a candidate template list according to the driving type;
[0008] obtaining an SQL file from the reference file, wherein the SQL file contains M SQL statements, and M is a positive integer;
[0009] For any SQL statement, the SQL statement is analyzed to obtain a syntax feature;
[0010] obtaining a mapping rule, and determining a target interface template of the SQL statement from the candidate template list based on the mapping rule and the syntax feature;
[0011] injecting the SQL statement into the target interface template to generate a driving use case.
[0012] In an optional implementation, the determining, based on the mapping rule and the syntax feature, of the target interface template of the SQL statement from the candidate template list comprises:
[0013] determining whether the mapping rule contains a target rule corresponding to the syntax feature;
[0014] In a case where the mapping rule contains the target rule corresponding to the syntax feature, determining the target interface template of the SQL statement from the candidate template list based on the target rule.
[0015] In an optional implementation, the method further comprises:
[0016] In a case where the reference file contains an interface framework file, determining N candidate interface templates according to the interface framework file and the drive type, N being a positive integer;
[0017] The determining, based on the mapping rule and the syntax feature, of the target interface template of the SQL statement from the candidate template list comprises:
[0018] The determining, based on the mapping rule and the syntax feature, of the target interface template of the SQL statement from the candidate template list, N candidate interface templates comprises:
[0019] In an optional implementation, the determining, according to the interface framework file and the drive type, of N candidate interface templates comprises:
[0020] generating N drive interface call chains by parsing the interface framework file based on the drive type;
[0021] For any drive interface call chain, encapsulating the drive interface call chain as a corresponding candidate interface template.
[0022] In an optional implementation, the determining, based on the mapping rule and the syntax feature, of the target interface template of the SQL statement from the candidate template list, N candidate interface templates comprises:
[0023] determining whether the mapping rule contains a target rule corresponding to the syntax feature;
[0024] In a case where the mapping rule contains the target rule corresponding to the syntax feature, determining the target interface template of the SQL statement from the candidate template list, N candidate interface templates based on the target rule.
[0025] In an optional implementation, the method further comprises:
[0026] In a case where the mapping rule does not contain a target rule corresponding to the syntax feature, a target interface template of the SQL statement is determined from the candidate template list, N candidate interface templates, based on the syntax feature.
[0027] In an optional embodiment, after the driving case is generated, the method further includes:
[0028] obtaining a database source information file from the reference file, the database source information file containing at least one database source information;
[0029] configuring a thread for the database source corresponding to any of the database source information;
[0030] The thread establishes a connection with the corresponding database source based on the driving case, executes the driving case, and generates an execution result.
[0031] In an optional embodiment, after the thread establishes a connection with the corresponding database source based on the driving case, executes the driving case, and generates an execution result, the method further includes:
[0032] comparing the execution result with an expected result file in the reference file to generate a comparison result;
[0033] generating a result report based on the execution result and the comparison result.
[0034] In a second aspect of the embodiments of the present application, a driving case generation device is further provided, and the device includes:
[0035] a first obtaining module that obtains a reference file and a driving type, and obtains a candidate template list according to the driving type;
[0036] a second obtaining module that obtains an SQL file from the reference file, the SQL file containing M SQL statements, M being a positive integer;
[0037] an analysis module that analyzes any of the SQL statements to obtain a syntax feature;
[0038] a determination module that obtains a mapping rule, and determines a target interface template of the SQL statement from the candidate template list based on the mapping rule and the syntax feature;
[0039] a generation module that injects the SQL statement into the target interface template to generate a driving case.
[0040] In a third aspect of the embodiments of the present application, an electronic device is further provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus.
[0041] The memory is configured to store a computer program.
[0042] The processor is configured to execute the program stored on the memory, and implement the driving case generation method in any one of the first aspect.
[0043] In a fourth aspect of the embodiments of the present application, a storage medium is further provided, and the storage medium stores instructions, which, when executed on a computer, cause the computer to execute the driving case generation method in any one of the first aspect.
[0044] In a fifth aspect of the embodiments of the present application, a computer program product containing instructions is further provided, which, when executed on a computer, cause the computer to execute the driving case generation method in any one of the first aspect.
[0045] The above technical solution provided by the embodiments of the present application acquires a reference file and a driving type, acquires a candidate template list according to the driving type, acquires an SQL file from the reference file, the SQL file contains M SQL statements, M is a positive integer, analyzes the SQL statements for any one SQL statement, obtains a syntax feature, acquires a mapping rule, and determines a target interface template of the SQL statement from the candidate template list based on the mapping rule and the syntax feature, injects the SQL statement into the target interface template, and generates a driving case. In this way, the target interface template is determined from the candidate template list based on the syntax feature and the mapping rule of the SQL statement, and the SQL statement is injected into the target interface template to generate the driving case, which can realize automatic conversion from the SQL statement to the driving case, improve the generation rate of the driving case, and avoid errors in the driving case caused by manual coding. BRIEF DESCRIPTION OF DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and serve to explain the principles of the present application together with the specification.
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.
[0048] Figure 1 An implementation flowchart of a driving case generation method provided by the embodiments of the present application is shown.
[0049] Figure 2 An implementation flowchart of a method for determining a target interface template provided by an embodiment of the present application is shown in the figure.
[0050] Figure 3 An implementation flowchart of another method for generating a driving use case provided by an embodiment of the present application is shown in the figure.
[0051] Figure 4 An implementation flowchart of a method for determining a candidate interface template provided by an embodiment of the present application is shown in the figure.
[0052] Figure 5 An implementation flowchart of another method for determining a candidate interface template provided by an embodiment of the present application is shown in the figure.
[0053] Figure 6 An implementation flowchart of a method for executing a driving use case provided by an embodiment of the present application is shown in the figure.
[0054] Figure 7 A structural diagram of a driving use case generation apparatus provided by an embodiment of the present application is shown in the figure.
[0055] Figure 8 A structural diagram of an electronic device provided by an embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0056] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in connection with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0057] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in connection with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0058] As shown in the figure, an implementation flowchart of a method for generating a driving use case provided by an embodiment of the present application is shown in the figure, which can specifically include the following steps: Figure 1
[0059] S101, a reference file and a driving type are acquired, and a candidate template list is acquired according to the driving type.
[0060] In the embodiments of the present application, the reference file and the driving type are acquired, and a candidate template list is acquired according to the driving type, wherein the reference file is provided by a user and is used to provide basic information for driving case generation, and can include an SQL file, an interface framework file, a database source information file, an expected result file, and the like.
[0061] The above SQL file stores an original SQL statement to be converted into a driving case, such as a query (SELECT), an insertion (INSERT), an update (UPDATE), a deletion (DELETE), and the like, which is not limited in the embodiments of the present application.
[0062] The above interface framework file contains a specification for defining an interface, including a parameter format (JSON, a key-value pair, and the like), a calling sequence (such as “connection->verification->execution->release”), a return value structure (such as a unified format containing a status code, a data body, and error information), and the like, and is used to generate an interface template conforming to a specific framework requirement, wherein a user can customize a driving interface framework (such as a PreparedStatement mode of JDBC) through a JSON file, and assign a special driving template for an SQL statement with a specific syntax feature (such as a table name, a function call), which is not limited in the embodiments of the present application.
[0063] The above database source information file records connection information (such as an IP address, a port, an account password, and the like) of a database, and is used for subsequent execution and verification of a driving case, which is not limited in the embodiments of the present application.
[0064] The above expected result file contains an expected output after execution of an SQL statement, and is used to compare an actual execution result to verify the correctness of a driving case, which is not limited in the embodiments of the present application.
[0065] The above driving type is used to distinguish different business scenarios and data processing requirements, and the driving type can include JDBC, ODBC, HTTP API, and the like, wherein JDBC is a standard interface for interaction between a Java program and a database, is suitable for a Java development environment, and supports operations of a relational database (such as MySQL, Oracle); ODBC is a cross-platform database access interface, is suitable for a Windows system and the like, and supports calling of multiple programming languages (such as C, Python); and HTTP API is an interface based on an HTTP protocol, is suitable for operation of a database through a network request (such as RESTful API calling of a cloud database), which is not limited in the embodiments of the present application.
[0066] The above candidate template list is a preset template set bound to the driver type, and each template corresponds to an interface calling scenario. The matched candidate template list is filtered from the template library according to the driver type. For example, if the driver type is JDBC, the candidate template list contains interface templates corresponding to JDBC, such as a PreparedStatement calling template, a transaction processing template, and the like. If the driver type is HTTP API, the candidate template list contains interface templates corresponding to HTTP API, such as a REST request template, a JSON parameterization template. If the driver type is ODBC, the candidate template list contains interface templates corresponding to ODBC, such as an ODBC connection template, a result set processing template.
[0067] S102, obtain an SQL file from the reference file, the SQL file containing M SQL statements, M being a positive integer.
[0068] In the embodiment of the present application, the SQL file containing M SQL statements is parsed into a structured statement set (such as a list, an array, or other data structure) by a syntax analysis tool (such as ANTLR, SQL Parser, or the like), and temporarily stored in the memory or cache.
[0069] The above SQL statements can be independent and each complete a specific database operation, or can be associated with each other, for example, a plurality of SQL statements are contained in a stored procedure, and the statements are executed in a certain logical order to implement complex business logic.
[0070] S103, for any SQL statement, analyze the SQL statement to obtain a syntax feature.
[0071] In the embodiment of the present application, for any SQL statement, the SQL statement is analyzed to obtain a syntax feature. The syntax analyzer can be used to analyze each SQL statement, split the SQL statement into various syntax units according to the syntax rules of the SQL language, including keywords (such as SELECT, FROM, WHERE, and the like), identifiers (such as table names, field names, and the like), operators (such as =, >, <, and the like), constants (such as specific numerical values, strings, and the like), and the like, and analyze the syntax relationship and hierarchical structure between the SQL statements to obtain the syntax feature of the SQL statement. The syntax feature can be the type of the SQL statement (such as SELECT, INSERT, UPDATE, DELETE, and the like), the table name and field name involved, the condition expression, the sorting manner, the grouping manner, and the like, which are not limited in the embodiment of the present application.
[0072] For example, for the SQL statement "SELECT * FROM users WHERE age > 20 ORDER BY name ASC", the syntax features of the SQL statement are identified by the syntax analyzer as a query statement (SELECT), the table involved is "users", the query condition is "age > 20", and the sorting manner is ascending order according to the "name" field.
[0073] In the embodiment of the present application, the mapping rule is obtained, and the target interface template of the SQL statement is determined from the candidate template list based on the mapping rule and the syntax features in the case where the reference file does not contain the interface framework file. The mapping rule can be pre-set and can include the defined relationship between the syntax features of the SQL statement and each interface template in the candidate template list.
[0074] In the embodiment of the present application, the mapping rule is obtained, and the target interface template of the SQL statement is determined from the candidate template list based on the mapping rule and the syntax features in the case where the reference file does not contain the interface framework file. The mapping rule can be pre-set and can include the defined relationship between the syntax features of the SQL statement and each interface template in the candidate template list.
[0075] For example, for the query statement "SELECT * FROM users WHERE age > 20 ORDER BY name ASC;", the syntax features indicate that the SQL statement is a query statement, and according to the mapping rule, the "PreparedStatement calling template" is determined as the target interface template of the SQL statement.
[0076] In the case where the reference file does not contain the interface framework file, how to determine the target interface template of the SQL statement from the candidate template list based on the mapping rule and the syntax features can refer to the method shown in Figure 2 As shown in Figure 2 The embodiment of the method for determining the target interface template provided by the present application is shown in the flowchart, which can include the following steps:
[0077] S201, determine whether the mapping rule contains the target rule corresponding to the syntax features.
[0078] In the embodiment of the present application, whether the mapping rule contains the target rule corresponding to the syntax features can be determined by comparing the syntax features of the SQL statement (such as the statement type, parameter type, and involved operation) with the feature conditions in the mapping rule one by one. If the feature conditions in the mapping rule contain the syntax features of the SQL statement, it is determined that the mapping rule contains the target rule corresponding to the syntax features. Otherwise, it is determined that the mapping rule does not contain the target rule corresponding to the syntax features.
[0079] For example, in the mapping rule, the feature condition of rule A is a query statement, and the corresponding interface template is "query type interface template A", and the feature condition of rule B is an insert statement, and the corresponding interface template is "insert type interface template B". If the syntax feature of the SQL statement is "statement type = SELECT", and rule A contains the syntax feature of the SQL statement, it is determined that the mapping rule contains the target rule corresponding to the syntax feature. If the syntax feature of the SQL statement is "statement type = DELETE", and there is no corresponding feature condition in the mapping rule, it is determined that the mapping rule does not contain the target rule corresponding to the syntax feature.
[0080] S202, in the case where the mapping rule contains the target rule corresponding to the syntax feature, determining the target interface template of the SQL statement from the candidate template list based on the target rule.
[0081] In the embodiment of the present application, in the case where the mapping rule contains the target rule corresponding to the syntax feature, the target interface template of the SQL statement is determined from the candidate template list based on the target rule.
[0082] For example, in the mapping rule, the feature condition of rule A is a query statement, and the corresponding interface template is "query type interface template A", and the feature condition of rule B is an insert statement, and the corresponding interface template is "insert type interface template B". If the syntax feature of the SQL statement is "statement type = SELECT", then rule A is selected as the target rule, and "query type interface template A" is selected as the target interface template from the candidate template list.
[0083] In addition, if the target interface template of one SQL statement corresponds to multiple feature conditions in the mapping rule, the corresponding target rule can be matched according to the last feature condition, so as to determine the target interface template of the SQL statement from the candidate template list based on the target rule.
[0084] And in the case where the mapping rule does not contain the target rule corresponding to the syntax feature, the target interface template of the SQL statement is determined from the candidate template list according to the syntax feature, for example, the DML statement (INSERT / UPDATE / DELETE) corresponds to the DML_Prepare_Interface interface template in the candidate template list; the DQL statement (SELECT) corresponds to the DQL_Default_interface interface template in the candidate template list; and the DDL statement (CREATE / DROP) corresponds to the DDLDefault Interface interface template in the candidate template list.
[0085] S105, injecting the SQL statement into the target interface template to generate a driving use case.
[0086] In the embodiment of the present application, the SQL statement is injected into the target interface template to generate the driving case. Among them, the SQL statement except the default handle application and chain building operation is injected and filled according to the requirements of the target interface template, including placing each part of the SQL statement (such as table name, field name, condition expression, etc.) to the corresponding position of the target interface template.
[0087] Meanwhile, the parameter passing and data type conversion can also be processed according to the specification of the target interface template. For example, if the target interface template requires the parameter to be passed in a specific data type, the parameter in the SQL statement is converted to the corresponding data type to ensure that the generated driving case conforms to the calling specification of the interface.
[0088] Through the above description of the technical solutions provided by the embodiments of the present application, the reference file and the driving type are obtained, the candidate template list is obtained according to the driving type, the SQL file is obtained from the reference file, the SQL file contains M SQL statements, M is a positive integer, for any SQL statement, the SQL statement is analyzed to obtain the syntax feature, the mapping rule is obtained, and based on the mapping rule and the syntax feature, the target interface template of the SQL statement is determined from the candidate template list, the SQL statement is injected into the target interface template to generate the driving case. In this way, based on the syntax feature and the mapping rule of the SQL statement, the target interface template is determined from the candidate template list, and the SQL statement is injected into the target interface template to generate the driving case, which can realize automatic conversion from the SQL statement to the driving case, improve the generation rate of the driving case, and avoid errors caused by manual coding.
[0089] As shown in FIG. 4, it is an implementation flow diagram of another driving case generation method provided by the embodiments of the present application, which can specifically include the following contents: Figure 3
[0090] S301, the reference file and the driving type are obtained, and the candidate template list is obtained according to the driving type.
[0091] In the embodiment of the present application, this step is similar to the above step S101, and the embodiments of the present application will not be described one by one here.
[0092] S302, the SQL file is obtained from the reference file, and the SQL file contains M SQL statements, M is a positive integer.
[0093] In the embodiment of the present application, this step is similar to the above step S102, and the embodiments of the present application will not be described one by one here.
[0094] S303, in the case that the reference file contains the interface framework file, N candidate interface templates are determined according to the interface framework file and the driving type, N is a positive integer.
[0095] In the embodiment of the present application, the interface framework file contains the specification defining the interface, including the parameter format (JSON, key-value pair, etc.), the calling sequence (such as "connection -> verification -> execution -> release"), the return value structure (such as a unified format containing the status code, data body, and error information), etc., which is used to generate the interface template conforming to the requirements of the specific framework. In this embodiment, the user can customize the driver interface framework (such as the PreparedStatement mode of JDBC) through the JSON file, and assign a dedicated driver template for the SQL statement with specific syntax features (such as table name, function call), which is not limited in the embodiment of the present application.
[0096] In the case where the reference file contains the interface framework file, the interface framework file is parsed according to the driver type (such as JDBC, ODBC) to determine N candidate interface templates adapted to the current driver type and framework specification, where N is a positive integer (such as N is 1, 2, 3, etc.), which is not limited in the embodiment of the present application.
[0097] For example, if the driver type is "JDBC" and the interface framework file defines the specification that "the database operation must contain log printing (calling LogUtil.log()) and connection timeout retry (up to 3 times)", then based on the interface framework file and the driver type, two candidate interface templates (i.e. N = 2) are generated: "JDBC query interface template (containing log and retry)" and "JDBC update interface template (containing log and retry)".
[0098] How to determine N candidate interface templates according to the interface framework file and the driver type can be specifically referred to the method shown in Figure 4 The embodiment of the method for determining the candidate interface template provided by the present application is shown in Figure 4 The embodiment of the method for determining the candidate interface template provided by the present application is shown in
[0099] S401, generating N driver interface calling chains based on the interface framework file and the driver type.
[0100] In the embodiment of the present application, the interface framework file contains the specification defining the interface, including the parameter format (JSON, key-value pair, etc.), the calling sequence (such as "connection -> verification -> execution -> release"), the return value structure (such as a unified format containing the status code, data body, and error information), etc., which is used to generate the interface template conforming to the requirements of the specific framework. In this embodiment, the user can customize the driver interface framework (such as the PreparedStatement mode of JDBC) through the JSON file, and assign a dedicated driver template for the SQL statement with specific syntax features (such as table name, function call), which is not limited in the embodiment of the present application.
[0101] For example, for the JDBC driver type, the interface framework file specifies that the database operation must be checked for permissions before the subsequent operation is performed. Therefore, when generating the driver interface call chain, the "permission check" step is added before the "get connection" step of the basic flow, forming the complete call chain of "permission check -> get connection -> create statement -> execute -> process result -> release resource".
[0102] S402, for any driver interface call chain, encapsulate the driver interface call chain into the corresponding candidate interface template.
[0103] In the embodiment of the present application, for any driver interface call chain, the driver interface call chain is encapsulated into the corresponding candidate interface template, and in the encapsulation process, each step in the driver interface call chain is converted into specific code and converted according to the parameter format and return value structure specified in the interface framework file.
[0104] For example, for the above generated "permission check -> get connection -> create statement -> execute -> process result -> release resource" driver interface call chain, when encapsulated into a candidate interface template, corresponding code is written for each step, such as the permission check step calling the corresponding permission verification interface, the get connection step using the JDBC Connection interface to get the database connection, etc. At the same time, the input method of the parameters and the output format of the return value are defined in the code to ensure that the generated candidate interface template meets the requirements of the interface framework file.
[0105] S304, for any SQL statement, analyze the SQL statement to obtain the syntax feature.
[0106] In the embodiment of the present application, this step is similar to the above step S103, and the embodiment of the present application will not be described one by one here.
[0107] S305, obtain the mapping rule, and determine the target interface template of the SQL statement from the candidate template list and the N candidate interface templates based on the mapping rule and the syntax feature.
[0108] In the embodiment of the present application, the mapping rule is obtained, and in the case that the reference file contains the interface framework file, the target interface template of the SQL statement is determined from the candidate template list and the N candidate interface templates based on the mapping rule and the syntax feature.
[0109] How to determine the target interface template of the SQL statement from the candidate template list and the N candidate interface templates based on the mapping rule and the syntax feature can be specifically referred to the method as shown in Figure 5 Another embodiment of the method for determining the candidate interface template provided by the embodiment of the present application is shown in Figure 5 The embodiment of the method for determining the candidate interface template provided by the embodiment of the present application is shown in
[0110] S501, determine whether the mapping rule contains a target rule corresponding to the syntax feature.
[0111] In the embodiments of the present application, whether the mapping rule contains a target rule corresponding to the syntax feature of the SQL statement can be determined by comparing the syntax feature of the SQL statement (such as the statement type, parameter type, and operation involved) with the feature condition in the mapping rule one by one. If the feature condition in the mapping rule contains the syntax feature of the SQL statement, it is determined that the mapping rule contains a target rule corresponding to the syntax feature. Otherwise, it is determined that the mapping rule does not contain a target rule corresponding to the syntax feature.
[0112] For example, in the mapping rule, the feature condition of rule A is a query statement, and the corresponding interface template is "query type interface template A". The feature condition of rule B is an insert statement, and the corresponding interface template is "insert type interface template B". If the syntax feature of the SQL statement is "statement type = SELECT", the mapping rule contains the syntax feature of the SQL statement, and it is determined that the mapping rule contains a target rule corresponding to the syntax feature. If the syntax feature of the SQL statement is "statement type = DELETE", there is no corresponding feature condition in the mapping rule, and it is determined that the mapping rule does not contain a target rule corresponding to the syntax feature.
[0113] S502, in the case where the mapping rule contains a target rule corresponding to the syntax feature, determining the target interface template of the SQL statement from the candidate template list and the N candidate interface templates based on the target rule.
[0114] In the embodiments of the present application, in the case where the mapping rule contains a target rule corresponding to the syntax feature, the target interface template of the SQL statement is determined from the candidate template list and the N candidate interface templates based on the target rule.
[0115] For example, from the candidate template list and the N candidate interface templates, an interface template matching the target rule A is found; from the candidate template list and the N candidate interface templates, an interface template matching the target rule B is found.
[0116] The above describes the steps in the case where the mapping rule contains a target rule corresponding to the syntax feature, and in the case where the mapping rule does not contain a target rule corresponding to the syntax feature, the target interface template of the SQL statement needs to be determined from the candidate template list and the N candidate interface templates based on the syntax feature.
[0117] For example, the syntax feature of the SQL statement is "statement type = DELETE", and there is no target rule corresponding to the syntax feature of the SQL statement in the mapping rule. At this time, the target interface template needs to be determined from the candidate template list and the N candidate interface templates according to the syntax feature of the SQL statement.
[0118] For example, the DML statement (INSERT / UPDATE / DELETE) corresponds to the DML_Prepare_Interface interface template in the candidate template list; the DQL statement (SELECT) corresponds to the DQL_Default_interface interface template in the candidate template list; and the DDL statement (CREATE / DROP) corresponds to the DDL DefaultInterface interface template in the candidate template list.
[0119] S306, inject the SQL statement into the target interface template to generate a driving use case.
[0120] In the embodiments of the present application, this step is similar to the above step S105, and the embodiments of the present application will not be repeated here.
[0121] In addition, after the driving use case is generated, the driving use case is executed, and a step of generating a corresponding execution result is performed. For details, refer to the method shown in Figure 6 As shown in Figure 6 An implementation flowchart of a driving use case execution method provided by the embodiments of the present application is shown in
[0122] S601, obtain a database source information file from a reference file, wherein the database source information file contains at least one database source information.
[0123] In the embodiments of the present application, the database source information file is obtained from the reference file, and the database source information file contains at least one database source information. The connection information (such as IP address, port, account password, etc.) of the database is recorded in the database source information file, which is used for subsequent execution and verification of the driving use case, and the embodiments of the present application are not limited thereto.
[0124] S602, for any database source information, configure a thread for the database source corresponding to the database source information.
[0125] In the embodiments of the present application, for any database source information, a thread is configured for the database source corresponding to the database source information. A thread pool can be created according to the number of database source information, and the thread pool is initialized as a thread. Each thread processes a corresponding single database source, ensuring that the connection and execution process of different databases do not interfere with each other. For example, thread A is configured for the first database source (192.168.1.100:3306), and thread B is configured for the second database source (10.0.0.2:1521).
[0126] For example, if the database source information file contains 3 database sources, the thread pool is initialized to 3 threads, each thread is bound to a database source and is in a waiting state to execute the driving case.
[0127] S603, the thread establishes a connection with the corresponding database source based on the driving case and executes the driving case to generate an execution result.
[0128] In the embodiment of the present application, the thread establishes a connection with the corresponding database source based on the driving case and executes the driving case to generate an execution result. The execution result can be in JSON or XML format, and the execution result contains the database source identifier, the execution status (failure or success), the execution result of each SQL (such as "insertion success, affected row number: 1"), the returned data set (such as the result set of the SELECT statement), and the performance indicators (such as execution time, CPU / memory occupation), which are not limited in the embodiment of the present application.
[0129] In addition, after the thread establishes a connection with the corresponding database source based on the driving case and executes the driving case to generate an execution result, it can also be judged whether the reference file contains an expected result file. The expected result file is the expected result (such as the expected returned data set, the affected row number, and the execution status) that should be output after the driving case is executed, and the format can be consistent with the execution result (such as JSON, XML), or a user-defined format (such as Excel, CSV).
[0130] The generated driving case can be executed in parallel on multiple database sources, and the consistency of the results and the expected results can be automatically verified.
[0131] If the reference file contains the expected result file, the execution result is compared with the expected result file to generate a comparison result, and a result report is generated based on the execution result and the comparison result. Specifically, the execution status, the affected row number, the returned data set, and the performance indicators can be compared to finally generate a result report. The result report can include basic information (test start / end time, reference file path, number of database sources, total number of driving cases), execution summary (number of successful cases, number of failed cases, number of unexecuted cases, average execution time), detailed comparison (comparison result of each database source and each test case), difference analysis (for "not expected" cases, specific difference items are listed), performance summary (average execution time, maximum execution time, CPU / memory occupation trend of each database source), and exception record (connection failure, case execution timeout, expected result file format error, and other abnormal events).
[0132] For example, each SQL statement in the execution result is matched with the corresponding entry in the expected result. If there is an SQL statement in the execution result that is not covered by the expected result, it is marked as "unexpected"; if there is an SQL statement in the expected result that is not covered by the execution result, it is marked as "not executed".
[0133] Corresponding to the above method embodiments, this application also provides a driver use case generation device, such as... Figure 7 As shown, the device may include a first acquisition module 701, a second acquisition module 702, an analysis module 703, a determination module 704, and a generation module 705.
[0134] The first acquisition module 701 acquires the reference file and driver type, and obtains a candidate template list based on the driver type;
[0135] The second acquisition module 702 acquires an SQL file from the reference file. The SQL file contains M SQL statements, where M is a positive integer.
[0136] Analysis module 703 analyzes any given SQL statement to obtain its syntactic features;
[0137] Module 704 is identified, mapping rules are obtained, and based on the mapping rules and syntax features, the target interface template for the SQL statement is determined from the candidate template list.
[0138] Module 705 injects SQL statements into the target interface template to generate driver test cases.
[0139] This application also provides an electronic device, such as... Figure 8 As shown, it includes a processor 801, a communication interface 802, a memory 803, and a communication bus 804. The processor 801, communication interface 802, and memory 803 communicate with each other via the communication bus 804.
[0140] Memory 803 is used to store computer programs;
[0141] In one embodiment of this application, when the processor 801 executes a program stored in the memory 803, it performs the following steps:
[0142] Obtain the reference file and driver type, and obtain a candidate template list based on the driver type. Obtain the SQL file from the reference file, which contains M SQL statements, where M is a positive integer. For any SQL statement, analyze the SQL statement to obtain its syntax features and mapping rules. Based on the mapping rules and syntax features, determine the target interface template of the SQL statement from the candidate template list, inject the SQL statement into the target interface template, and generate driver use cases.
[0143] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.
[0144] The communication interface is used for communication between the electronic device and other devices.
[0145] The memory can include a Random Access Memory (RAM) and can also include a non-volatile memory, such as at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0146] The processor mentioned above can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; can also be a Digital Signal Processing (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
[0147] In another embodiment provided in the present application, a storage medium is also provided, and the storage medium stores instructions, and when the instructions run on a computer, the computer executes the driving case generation method in any of the above embodiments.
[0148] In another embodiment provided in the present application, a computer program product containing instructions is also provided, and when the instructions run on a computer, the computer executes the driving case generation method in any of the above embodiments.
[0149] In the embodiments described above, all or some of the steps can be implemented by hardware, software, firmware or any combination thereof. When implemented in software, all or some of the steps can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed by a computer, the computer program instructions cause the computer to perform all or some of the steps as described in the embodiments. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatuses. The computer instructions can be stored in a storage medium or transmitted from one storage medium to another storage medium. For example, the computer instructions can be transmitted from a website, a computer, a server or a data center to another website, computer, server or data center through a wired (such as a coaxial cable, an optical fiber, a digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner. The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0150] It should be noted that the relative terms such as first and second, etc., are used herein only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "contain" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such a process, method, article or device. Without more limitations, the element defined by the statement "comprises a" does not exclude the presence of additional identical elements in the process, method, article or device including the element.
[0151] Each of the embodiments in the specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.
[0152] The above only describes the preferred embodiments of the present application, and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A driving case generation method characterized by comprising: The method includes: Obtain the reference file and driver type, and obtain a candidate template list based on the driver type; Obtain an SQL file from the reference file, the SQL file containing M SQL statements, where M is a positive integer; For any of the SQL statements, the SQL statements are analyzed to obtain their syntactic features; Obtain the mapping rules, and based on the mapping rules and the syntax features, determine the target interface template for the SQL statement from the candidate template list; The SQL statement is injected into the target interface template to generate driver test cases.
2. The method of claim 1, wherein, The step of determining the target interface template for the SQL statement from the candidate template list based on the mapping rules and the syntax features includes: Determine whether the mapping rule contains the target rule corresponding to the syntax feature; If the mapping rule includes the target rule corresponding to the syntax feature, the target interface template of the SQL statement is determined from the candidate template list based on the target rule.
3. The method of claim 1, wherein, The method further includes: If the reference file contains an interface framework file, N candidate interface templates are determined based on the interface framework file and the driver type, where N is a positive integer. The step of determining the target interface template for the SQL statement from the candidate template list based on the mapping rules and the syntax features includes: Based on the mapping rules and the syntax features, the target interface template for the SQL statement is determined from the candidate template list and N candidate interface templates.
4. The method of claim 3, wherein, The step of determining N candidate interface templates based on the interface framework file and the driver type includes: Based on the driver type, the interface framework file is parsed to generate N driver interface call chains; For any of the aforementioned driver interface call chains, the driver interface call chain is encapsulated into the corresponding candidate interface template.
5. The method of claim 3, wherein, The step of determining the target interface template for the SQL statement from the candidate template list and N candidate interface templates based on the mapping rules and the syntax features includes: Determine whether the mapping rule contains the target rule corresponding to the syntax feature; If the mapping rule includes the target rule corresponding to the syntax feature, the target interface template of the SQL statement is determined from the candidate template list and N candidate interface templates based on the target rule.
6. The method of claim 5, wherein, The method further includes: If the target rule corresponding to the syntax feature is not included in the mapping rule, the target interface template of the SQL statement is determined from the candidate template list and N candidate interface templates based on the syntax feature.
7. The method according to claim 1 or 3, characterized in that, Following the generation of driver use cases, the following is also included: Obtain a database source information file from the reference file, wherein the database source information file contains at least one database source information; For any of the aforementioned database source information, configure a thread for the database source corresponding to the database source information; The thread establishes a connection with the corresponding database source based on the driver use case, executes the driver use case, and generates an execution result.
8. The method of claim 7, wherein, After the thread establishes a connection with the corresponding database source end based on the driving case and executes the driving case to generate an execution result, the method further includes: If the reference file contains an expected result file, comparing the execution result with the expected result file to generate a comparison result; Generating a result report based on the execution result and the comparison result.
9. A driving case generation apparatus characterized by comprising: The apparatus includes: A first obtaining module that obtains a reference file and a driving type, and obtains a candidate template list according to the driving type; A second obtaining module that obtains an SQL file from the reference file, the SQL file containing M SQL statements, M being a positive integer; An analyzing module that analyzes any SQL statement to obtain a syntax feature; A determining module that obtains a mapping rule, and determines a target interface template of the SQL statement from the candidate template list based on the mapping rule and the syntax feature; A generating module that injects the SQL statement into the target interface template to generate a driving case.
10. An electronic device, comprising: The apparatus includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store a computer program; The processor is used to execute the program stored on the memory to implement the method of any one of claims 1-8.