CN118113681A - Method, apparatus, device, and computer-readable storage medium for database testing - Google Patents

Method, apparatus, device, and computer-readable storage medium for database testing Download PDF

Info

Publication number
CN118113681A
CN118113681A CN202410132289.6A CN202410132289A CN118113681A CN 118113681 A CN118113681 A CN 118113681A CN 202410132289 A CN202410132289 A CN 202410132289A CN 118113681 A CN118113681 A CN 118113681A
Authority
CN
China
Prior art keywords
instantiation
query language
structured query
preset
statement
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410132289.6A
Other languages
Chinese (zh)
Inventor
赵晓龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202410132289.6A priority Critical patent/CN118113681A/en
Publication of CN118113681A publication Critical patent/CN118113681A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application provides a database testing method, device, equipment and computer readable storage medium, relating to the technical field of software program testing. The method comprises the following steps: acquiring a loaded preset structured query language statement through a preset application programming interface, wherein the preset structured query language statement comprises an input parameter type; instantiating the preset structured query language sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence; executing the target database operation statement in a target database through a preset application programming interface; and acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.

Description

Method, apparatus, device, and computer-readable storage medium for database testing
Technical Field
The present application relates to the field of software program testing technology, and in particular, to a method, an apparatus, a device, a computer readable storage medium and a computer program product for database testing.
Background
In the current information age, various information is generally stored in the form of a database. The most widely used at present is the structured query language (Structured Query Language, SQL) database, which needs to be operated and used by SQL statements.
In the process of modifying the information system, if the database needs to be replaced, a large number of SQL sentences and database adaptation may be involved. In the related art, a batch unit testing method and a static scanning SQL statement mode are adopted for testing and verification. Each SQL statement in the batch unit test should have a corresponding programming language method, and if there is no corresponding programming language method, the test and verification cannot cover the SQL statement. The method of statically scanning SQL sentences can only be matched through keywords, is only suitable for simple SQL sentences, and has poor accuracy in testing and verification of complex SQL sentences.
Disclosure of Invention
The application provides a database testing method, a database testing device, database testing equipment and a computer readable storage medium, which can accurately test and verify complex SQL sentences.
In a first aspect, the present application provides a method of database testing, the method comprising:
acquiring a loaded preset structured query language statement through a preset application programming interface, wherein the preset structured query language statement comprises an input parameter type;
instantiating the preset structured query language sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence;
executing the target database operation statement in a target database through a preset application programming interface;
and acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.
According to the embodiment of the application, the preset structured query language statement is obtained by using the preset application programming interface, and then the corresponding instantiation object and parameter are generated according to the structured query language statement. And obtaining a target database operation statement by the obtained instantiation object and the parameters, and operating the target database operation statement so as to test and verify the structured query language statement, thereby obtaining a test result. The adaptation test of the structured query language statement can be automatically carried out, and the comprehensiveness and accuracy of the test are improved.
In some possible implementations, instantiating the preset structured query language sentence according to the input parameter type and the mapping relationship information between the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence, including:
determining whether the preset structured query language statement is a branch statement according to the target character;
under the condition that the preset structured query language sentence is a branch sentence, obtaining structured query language sentences corresponding to different branches;
Based on the input parameter types in the structured query language sentences and the mapping relation information of the input parameter types and the instantiation parameters included in the preset application program, instantiating the preset structured query language sentences to obtain target database operation sentences.
The method of the embodiment of the application carries out instantiation on specific sentences in different branches of the branch sentences by judging whether the structured query language sentences are branch sentences or not, and obtains the target database operation sentences for testing. The comprehensiveness of the test can be ensured.
In some possible implementations, the instantiating the preset structured query language statement to obtain a target database operation statement includes:
determining a corresponding instantiation object according to an instantiation type corresponding to the preset structured query language statement;
According to a preset instantiation parameter list, determining the parameter type in the instantiation object;
and determining the parameters corresponding to the parameter types as default values, and carrying out object instantiation to obtain a target database operation statement.
The above-described manner of embodiments of the present application determines different instantiation objects from different structured query language statements. And then, according to a preset instantiation parameter list, determining the parameter type in the instantiation object, and further carrying out the instantiation of the object. The instantiation can be accurately performed to obtain a proper target database operation statement.
In some possible implementations, after the determining the parameter type in the instantiation object according to the preset instantiation parameter list, the method further includes:
According to a preset instantiation parameter list, determining a parameter type field value corresponding to a parameter type in the instantiation object;
And constructing a default value of the instantiation object parameter according to the parameter type field value.
The above-described manner of embodiments of the present application constructs default values for instantiation object parameters from parameter type field values in the instantiation parameter list. An accurate parameter value can be obtained and instantiation is performed based on the parameter value.
In some possible implementations, the instantiation types include a general type and a complex type, and the performing the instantiation of the object includes:
Traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a common type to obtain a corresponding instantiation field;
and creating a corresponding instantiation object according to the instantiation field.
The method of the embodiment of the application directly traverses the condition of the common type by judging the instantiation type corresponding to the structured query language statement so as to obtain the corresponding instantiation object. Instantiation can be performed quickly.
In some possible implementations, the creating the corresponding instantiation object further includes:
traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a complex type;
traversing the traversed preset structured query language statement under the condition that the instantiation type corresponding to the traversed preset structured query language statement is of a complex type;
Traversing the preset structured query language sentence to obtain a corresponding instantiation field under the condition that the traversed instantiation type corresponding to the preset structured query language sentence is a common type;
and creating a corresponding instantiation object according to the instantiation field.
The above manner of the embodiment of the application continuously traverses the corresponding structured query language sentence under the condition that the instantiation type is the complex type, and the instantiation is not performed until the complex type is disassembled into the common type. The instantiation can be accurately and comprehensively completed.
In some possible implementations, after the obtaining the execution result of the target database operation statement executed on the target database to obtain a test result, the method further includes:
Determining a problem structured query language statement according to the execution condition in the test result;
And generating a problem statement report through the problem structured query language statement.
According to the method, the structural query language statement of the problem is determined according to the test result, and then a problem statement report is obtained. The statement of the problem in the test can be accurately displayed to the user.
In a second aspect, the present application provides an apparatus for database testing, the apparatus comprising:
The acquisition module is used for acquiring loaded preset structured query language sentences through a preset application programming interface, wherein the preset structured query language sentences comprise input parameter types;
The instance module is used for instantiating the preset structured query language sentence to obtain a target database operation sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program;
the execution module is used for executing the target database operation statement in a target database through a preset application programming interface;
The acquisition module is further used for acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.
In a third aspect, an embodiment of the present application provides an apparatus for testing a database, the apparatus including: a processor and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the method of database testing as described above.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement a method of database testing as described above.
In a fifth aspect, embodiments of the present application provide a computer program product, instructions in which, when executed by a processor of an electronic device, enable the electronic device to perform a method of database testing of any one of the above.
The method, the device, the equipment, the computer readable storage medium and the computer program product for testing the database provided by the embodiment of the application acquire a preset structured query language sentence through using a preset application programming interface, wherein the preset structured query language sentence comprises an input parameter type, further according to the input parameter type in the preset structured query language sentence and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program, instantiating the preset structured query language sentence to acquire a target database operation sentence, then executing the target database operation sentence in the target database through the preset application programming interface, so as to test and verify the structured query language sentence, and acquiring an execution result of executing the target database operation sentence in the target database to acquire a test result. By the test mode, the adaptation test of the structured query language statement can be automatically carried out, and the comprehensiveness and accuracy of the test are improved.
Drawings
The application will be better understood from the following description of specific embodiments thereof, taken in conjunction with the accompanying drawings, in which:
Other features, objects and advantages of the present application will become more apparent upon reading the following detailed description of non-limiting embodiments thereof, taken in conjunction with the accompanying drawings in which like or similar reference characters designate the same or similar features.
FIG. 1 is a flow chart of a method for database testing provided by one embodiment of the present application;
FIG. 2 is a flow chart of another method for database testing provided by one embodiment of the present application;
FIG. 3 is a flow chart of another method for database testing provided by one embodiment of the present application;
FIG. 4 is a schematic diagram of an apparatus for database testing according to an embodiment of the present application;
Fig. 5 is a schematic hardware structure of a database testing device according to an embodiment of the present application.
Detailed Description
Features and exemplary embodiments of various aspects of the application are described in detail below. In the following detailed description, numerous specific details are set forth in order to provide a thorough understanding of the application. It will be apparent, however, to one skilled in the art that the present application may be practiced without some of these specific details. The following description of the embodiments is merely intended to provide a better understanding of the application by showing examples of the application. The present application is in no way limited to any particular configuration and algorithm set forth below, but rather covers any modification, substitution, and improvement of elements, components, and algorithms without departing from the spirit of the application. In the drawings and the following description, well-known structures and techniques have not been shown in order to avoid unnecessarily obscuring the present application.
It should be noted that, in the technical scheme of the application, the acquisition, storage, use, processing and the like of the data all conform to the relevant regulations of national laws and regulations.
JavaAgent: javaAgent can monitor and modify the behavior of running Java applications, developers can dynamically load Java classes at application start-up, modify the bytecode of existing classes, and inject code into running applications.
MyBatis: is a Java-based persistent framework. Custom SQL, stored procedures, and advanced mapping are supported. The native information may be configured and mapped using simple XML or annotations, mapping the interface and Java's generic Java objects (Plain Ordinary Java Object, POJO) into records in a database.
In the current information age, various information is generally stored in the form of a database. The most widely used at present is the structured query language (Structured Query Language, SQL) database, which needs to be operated and used by SQL statements.
In the process of modifying the information system, if the database needs to be replaced, a large number of SQL sentences and database adaptation may be involved. In this process, a large number of tests are required to verify its correctness.
In the related art, a batch unit testing method and a static scanning SQL statement mode are adopted for testing and verification. Each SQL statement in the batch unit test should have a corresponding programming language method, and if there is no corresponding programming language method, the test and verification cannot cover the SQL statement. The method of statically scanning SQL sentences can only be matched through keywords, is only suitable for simple SQL sentences, and has poor accuracy in testing and verification of complex SQL sentences.
The inventor researches the problems to find that the target database operation statement is obtained by directly instantiating according to the original database statement, and then the target database operation statement is executed to test, so that the original database statement can be actually tested one by one, and the accuracy of the test is ensured.
In one embodiment of the method for testing a database according to the present application, referring to fig. 1, in this embodiment, the method may be performed by the apparatus for testing a database as described above, and the method includes the following steps S101 to S104.
Step S101: and acquiring the loaded preset structured query language statement through a preset application programming interface, wherein the preset structured query language statement comprises an input parameter type.
The preset application programming interface may be a set of predefined methods, functions, protocols, and tool sets provided in software development for the convenience of a developer to use and integrate a function or service. By invoking these APIs, a developer may interact with a third party library, framework, operating system, or other software component to implement a particular function or access a particular resource.
In a specific implementation, the API may be used to query a list of loaded SQL statements to obtain their input parameter types. These input parameter types are typically specified in placeholders of SQL statements. For example, an SQL statement may contain an integer type placeholder, indicating that the parameter to which the placeholder corresponds should be an integer type value.
Step S102: and instantiating the preset structured query language sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence.
Instantiation may refer to the process of creating a particular instance or object from a definition or template. In software development, instantiation typically involves instantiating a class or data structure into a specific object.
The target database operation statement may be a corresponding database statement or command for executing an operation on the target database. These statements are used to create, query, update, or delete data in the database to meet the needs of an application or system.
In a specific implementation, the preset application program includes mapping relation information of an input parameter type and an instantiation parameter, which is used for determining the type of the parameter. After the application program obtains the type of each input parameter, the instantiation parameter is matched with the corresponding type. Once the type and corresponding instantiation parameter value of each parameter are determined, the target database operation statement is obtained by instantiating the corresponding object of the target database operation statement according to the instantiation parameter value.
Step S103: and executing the target database operation statement in the target database through a preset application programming interface.
In particular implementations, an application may create a database connection object. The object represents a connection between an application and a database and provides a method of interacting with the database. By the method of connecting objects through the database, the application program can execute the target database operation statement. And calling an execution method of the database connection object to enable the prepared statement to be executed in the target database.
Step S104: and acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.
The execution result may be information or data returned after execution of the target database operation statement.
In particular implementations, after executing the target database operation statement, the API returns execution results, which are typically an execution state information or a result set. These results may be obtained by methods provided by the API. For example, if a query operation is performed, the result may be a result set object containing the query results; if an insert, update or delete operation is performed, the result may be an integer value representing the number of rows affected. According to specific requirements and business logic, the execution result needs to be analyzed. For example, for a query operation, the result set may be traversed and the required data extracted; for insert, update or delete operations, it may be checked whether the number of affected rows returned meets expectations. Once the execution results are obtained, the test results may be recorded. The test results, which typically include information on execution time, execution status, number of affected rows, etc., may be saved in a log file or database.
According to the method, the preset structured query language statement is obtained through the preset application programming interface, the preset structured query language statement is instantiated to obtain the target database operation statement according to the input parameter type in the preset structured query language statement and the mapping relation information of the input parameter type and the instantiation parameter in the preset application program, the target database operation statement is executed in the target database through the preset application programming interface, so that the structured query language statement is tested and verified, the execution result of the target database operation statement is obtained, the test result is obtained, the automatic adaptation test of the structured query language statement is realized, and the comprehensiveness and the accuracy of the test are improved.
In some embodiments, instantiating the preset structured query language sentence according to the input parameter type and the mapping relationship information between the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence, including:
And determining whether the preset structured query language statement is a branch statement according to the target character.
The target character may be an identifier, a keyword, or a specific syntax structure for determining whether the database statement is a branch statement. The specific definition depends on the actual requirements and business logic, and can be defined according to different situations.
In a specific implementation, the SQL statement needs to be parsed into different components, such as keywords, table names, column names, conditions, etc. And determining whether the SQL sentence is a target character of the branch sentence or not according to a preset definition. In general, some common key or syntax structures may be considered, such as IF, CASE where, WHILE, etc. Traversing the analysis result in the SQL sentence, and checking whether the target character exists. If the target character exists, the SQL statement can be considered a branch statement; if the target character does not exist, the SQL statement may be considered not a branch statement.
And under the condition that the preset structured query language sentence is a branch sentence, obtaining the structured query language sentence corresponding to each different branch.
In a specific implementation, if the SQL statement is determined to be a branch statement, corresponding branch logic processing is performed according to the type and grammar of the branch statement. For example, for IF statements, different SQL logic may be executed depending on the true or false of the IF condition; for the CASE WHEN statement, different results can be returned according to different conditions; for loop statements, SQL logic may be executed multiple times depending on the loop conditions. During the processing of the branching logic, the SQL statement corresponding to each branch can be stored in a corresponding data structure.
Based on the input parameter types in the structured query language sentences and the mapping relation information of the input parameter types and the instantiation parameters included in the preset application program, instantiating the preset structured query language sentences to obtain target database operation sentences.
In a specific implementation, mapping relation information of input parameter types and instantiation parameters is obtained from a preset application program. Such information is typically stored in a configuration file or database for dynamic modification. For example, a parameter mapping table may be defined, which includes information such as parameter names, parameter types, default values, etc. And carrying out instantiation according to the mapping relation information of the input parameter type and the instantiation parameter to obtain a target database operation statement.
The method of the embodiment of the application carries out instantiation on specific sentences in different branches of the branch sentences by judging whether the structured query language sentences are branch sentences or not, and obtains the target database operation sentences for testing. The comprehensiveness of the test can be ensured.
In some embodiments, referring to fig. 2, the method instantiates the preset structured query language statement to obtain a target database operation statement, and includes the following steps S201 to S203.
Step S201: and determining a corresponding instantiation object according to the instantiation type corresponding to the preset structured query language statement.
An instantiation type may be a type or class that creates a particular object. It is a special form of abstract type that can be instantiated to create a concrete object and operate using the attributes and methods of the object.
In a specific implementation, a data structure may be established for storing a mapping relationship between preset SQL statements and instantiation types. This may be achieved by a configuration file, a database table or a mapping table in the code. The mapping relationship may be one-to-one or one-to-many. And for different SQL sentences, determining the instantiation type corresponding to the preset SQL sentence. And thus determines the corresponding instantiation object.
Step S202: and determining the parameter type in the instantiation object according to a preset instantiation parameter list.
In a specific implementation, a corresponding constructor may be defined first, in the list of parameters of the constructor, the type of each parameter needs to be specified explicitly. These types may be predefined data types, or custom classes or types. When a constructor is called, a parameter value matching the type in the constructor parameter list needs to be entered. These parameter values will be used to instantiate the object and initialize according to type.
Step S203: and determining the parameters corresponding to the parameter types as default values, and carrying out object instantiation to obtain a target database operation statement.
In a specific implementation, a default value is set for each parameter. These default values will be used when creating the instantiation object, if the user does not provide parameters, the default values are used. When the constructor is invoked and no parameters are passed, default values will be used to create instantiation objects. If the user provides a parameter, the default value is updated with the provided value and then instantiated. Thereby obtaining the target database operation statement.
The above-described manner of embodiments of the present application determines different instantiation objects from different structured query language statements. And then, according to a preset instantiation parameter list, determining the parameter type in the instantiation object, and further carrying out the instantiation of the object. The instantiation can be accurately performed to obtain a proper target database operation statement.
In some embodiments, after determining the parameter type in the instantiation object according to the preset instantiation parameter list, the method further includes:
and determining a parameter type field value corresponding to the parameter type in the instantiation object according to a preset instantiation parameter list.
In a specific implementation, the instantiation object is created using parameters specified in the instantiation parameter list. If the parameter values in the instantiated parameter list are incorrect, an exception or error may be raised. Once the instantiated object is successfully created, the parameter type field value corresponding to the parameter type is automatically determined and can be accessed through the attribute and the method of the instantiated object.
And constructing a default value of the instantiation object parameter according to the parameter type field value.
In a specific implementation, when the constructor is invoked, if no parameters are provided, the instantiation object is created using the parameter type field value as a default value for the parameter.
The above-described manner of embodiments of the present application constructs default values for instantiation object parameters from parameter type field values in the instantiation parameter list. An accurate parameter value can be obtained and instantiation is performed based on the parameter value.
In some embodiments, the instantiation types include a general type and a complex type, and the performing the instantiation of the object includes:
And traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a common type to obtain a corresponding instantiation field.
In a specific implementation, a query operation is performed on an SQL statement and a set of query results is traversed. For each row of query results, the corresponding field value may be obtained by accessing a field name or index.
And creating a corresponding instantiation object according to the instantiation field.
The method of the embodiment of the application directly traverses the condition of the common type by judging the instantiation type corresponding to the structured query language statement so as to obtain the corresponding instantiation object. Instantiation can be performed quickly.
In some embodiments, the creating the corresponding instantiation object further includes:
And traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a complex type.
And traversing the traversed preset structured query language statement under the condition that the instantiation type corresponding to the traversed preset structured query language statement is of a complex type.
And under the condition that the traversed instantiation type corresponding to the preset structured query language statement is the common type, traversing the preset structured query language statement to obtain a corresponding instantiation field.
And creating a corresponding instantiation object according to the instantiation field.
In a specific implementation, for a complex type, for example, a java bean type, after traversing all branches, if there is a complex type in the branches, traversing the complex type again, so traversing continuously until the traversing results are all the common type. And finally, creating corresponding instantiation objects according to the obtained common types one by one.
The above manner of the embodiment of the application continuously traverses the corresponding structured query language sentence under the condition that the instantiation type is the complex type, and the instantiation is not performed until the complex type is disassembled into the common type. The instantiation can be accurately and comprehensively completed.
In some embodiments, referring to fig. 3, after the obtaining the execution result of the target database operation sentence executed in the target database to obtain a test result, the method further includes the following steps S301 to S302.
Step S301: and determining the problem structured query language statement according to the execution condition in the test result.
In a particular implementation, for each statement that is executed, its execution results need to be checked to determine if it meets expectations. The execution results may include data query results, error information, number of rows affected, and so forth. Based on the execution result, analyzing and judging the problem, and determining the SQL sentence of the problem.
Step S302: and generating a problem statement report through the problem structured query language statement.
In a specific implementation, the problem structured query language statement is analyzed to generate a problem statement report. The report may contain problem SQL statements, error information, data status, and the like.
According to the method, the structural query language statement of the problem is determined according to the test result, and then a problem statement report is obtained. The statement of the problem in the test can be accurately displayed to the user.
As another implementation of the present application, javaAgent may be used to connect to the target process of the database when testing is required. Then all the loaded SQL is obtained through an API provided by mybatis to be tested, and parameter initialization is carried out for each SQL. Each SQL has a corresponding input parameter type, and the corresponding type can be a simple java type or a complex java bean. By instantiating the parameter types, as input parameters when actually performing database operations, multiple instantiation parameters may be generated for the same SQL.
Specifically, each field is assigned to a default value so as to carry out parameter instantiation, and for a simple java type, the parameter instantiation can be carried out through a mapping table. For example, the bootan type corresponds to false; the Date type corresponds to new Date (); map type corresponds to NEW HASHMAP (), and so on.
For complex types, such as java beans, the instantiation is first as a null object, and then all fields are traversed for instantiation in sequence. Each field may be of a simple type and a complex type, so instantiating the object is a recursive process. For example, for if judgment sentences, the result of each if judgment is true as much as possible. When there are multiple if branches, different SQL will be generated if the value of a field is 0/1/2, and in this scenario, 3 instantiation parameters will be generated, where the value of the field is 0/1/2.
Each SQL is then executed through an API provided by mybatis. Either commit or rollback SQL execution may be selected. And collecting an execution result. If SQL can be executed correctly, this SQL grammar is indicated to be correct, otherwise this SQL may have grammar problems.
According to the scheme, through JavaAgent modes, each SQL can be truly executed through APIs provided by mybatis, and whether each SQL has grammar problems can be accurately verified.
Based on the database testing method provided by the embodiment, correspondingly, the application further provides a specific implementation mode of the database testing device. Please refer to the following examples.
Referring first to fig. 4, an apparatus 400 for database testing according to an embodiment of the present application includes the following modules:
the obtaining module 401 is configured to obtain, through a preset application programming interface, a loaded preset structured query language sentence, where the preset structured query language sentence includes an input parameter type.
The instance module 402 is configured to instantiate the preset structured query language sentence according to the input parameter type and mapping relation information between the input parameter type and the instantiation parameter included in the preset application program, to obtain a target database operation sentence.
And the execution module 403 is configured to execute the target database operation statement in a target database through a preset application programming interface.
The obtaining module 401 is further configured to obtain an execution result of executing the target database operation statement in the target database, so as to obtain a test result.
According to the embodiment of the application, the preset structured query language statement is obtained by using the preset application programming interface, and then the corresponding instantiation object and parameter are generated according to the structured query language statement. And obtaining a target database operation statement by the obtained instantiation object and the parameters, and operating the target database operation statement so as to test and verify the structured query language statement, thereby obtaining a test result. The adaptation test of the structured query language statement can be automatically carried out, and the comprehensiveness and accuracy of the test are improved.
As an implementation manner of the present application, the database testing apparatus 400 further includes:
And the determining module is used for determining whether the preset structured query language statement is a branch statement or not according to the target character.
The obtaining module 401 is further configured to obtain structured query language statements corresponding to different branches if the preset structured query language statement is a branch statement.
The instance module 402 is further configured to instantiate the preset structured query language sentence based on the input parameter types in the structured query language sentences and the mapping relationship information of the input parameter types and the instantiation parameters included in the preset application program, so as to obtain a target database operation sentence.
The method of the embodiment of the application carries out instantiation on specific sentences in different branches of the branch sentences by judging whether the structured query language sentences are branch sentences or not, and obtains the target database operation sentences for testing. The comprehensiveness of the test can be ensured.
As an implementation manner of the application, the determining module is further configured to determine a corresponding instantiation object according to an instantiation type corresponding to the preset structured query language statement.
The determining module is further used for determining the parameter type in the instantiation object according to a preset instantiation parameter list.
The instance module 402 is further configured to perform object instantiation by determining a parameter corresponding to the parameter type as a default value, so as to obtain a target database operation statement.
The above-described manner of embodiments of the present application determines different instantiation objects from different structured query language statements. And then, according to a preset instantiation parameter list, determining the parameter type in the instantiation object, and further carrying out the instantiation of the object. The instantiation can be accurately performed to obtain a proper target database operation statement.
As an implementation manner of the present application, the database testing apparatus 400 further includes:
The determining module is further configured to determine a parameter type field value corresponding to a parameter type in the instantiation object according to a preset instantiation parameter list.
And the construction module is used for constructing the default value of the instantiation object parameter according to the parameter type field value.
The above-described manner of embodiments of the present application constructs default values for instantiation object parameters from parameter type field values in the instantiation parameter list. An accurate parameter value can be obtained and instantiation is performed based on the parameter value.
As an implementation manner of the present application, the database testing apparatus 400 further includes:
The traversing module is used for traversing the preset structured query language sentence to obtain a corresponding instantiation field under the condition that the instantiation type corresponding to the preset structured query language sentence is a common type;
and the creation module is used for creating a corresponding instantiation object according to the instantiation field.
The method of the embodiment of the application directly traverses the condition of the common type by judging the instantiation type corresponding to the structured query language statement so as to obtain the corresponding instantiation object. Instantiation can be performed quickly.
The traversing module is further configured to traverse the preset structured query language sentence when the instantiation type corresponding to the preset structured query language sentence is a complex type.
The traversing module is further configured to traverse the traversed preset structured query language sentence when the instantiation type corresponding to the traversed preset structured query language sentence is a complex type.
The traversing module is further configured to traverse the preset structured query language sentence to obtain a corresponding instantiation field when the traversed instantiation type corresponding to the preset structured query language sentence is a common type.
The creation module is further used for creating a corresponding instantiation object according to the instantiation field.
The above manner of the embodiment of the application continuously traverses the corresponding structured query language sentence under the condition that the instantiation type is the complex type, and the instantiation is not performed until the complex type is disassembled into the common type. The instantiation can be accurately and comprehensively completed.
As an implementation manner of the present application, the database testing apparatus 400 further includes:
And the determining module is also used for determining the problem structured query language statement according to the execution condition in the test result.
And the generation module is used for generating a problem statement report through the problem structured query language statement.
According to the method, the structural query language statement of the problem is determined according to the test result, and then a problem statement report is obtained. The statement of the problem in the test can be accurately displayed to the user.
The modules in the database testing device provided by the embodiment of the application can realize the steps in the database testing method and achieve the corresponding effects, and are not repeated for brevity.
Fig. 5 shows a schematic structural diagram of hardware for database testing according to an embodiment of the present application.
The device tested in the database may comprise a processor 501 and a memory 502 storing computer program instructions.
In particular, the processor 501 may include a Central Processing Unit (CPU), or an Application SPECIFIC INTEGRATED Circuit (ASIC), or may be configured as one or more integrated circuits that implement embodiments of the present application.
Memory 502 may include mass storage for data or instructions. By way of example, and not limitation, memory 502 may comprise a hard disk drive (HARD DISK DRIVE, HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or universal serial bus (Universal Serial Bus, USB) drive, or a combination of two or more of the foregoing. Memory 502 may include removable or non-removable (or fixed) media, where appropriate. Memory 502 may be internal or external to the integrated gateway disaster recovery device, where appropriate. In a particular embodiment, the memory 502 is a non-volatile solid state memory.
The memory may include Read Only Memory (ROM), random Access Memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical, or other physical/tangible memory storage devices. Thus, in general, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software comprising computer-executable instructions and when the software is executed (e.g., by one or more processors) it is operable to perform the operations described with reference to a method of database testing according to any of the embodiments of the present disclosure.
The processor 501 implements the method of database testing of any of the above embodiments by reading and executing computer program instructions stored in the memory 502.
In one example, the database testing device may also include a communication interface 503 and a bus 510. As shown in fig. 5, the processor 501, the memory 502, and the communication interface 503 are connected to each other by a bus 510 and perform communication with each other.
The communication interface 503 is mainly used to implement communication between each module, apparatus, unit and/or device in the embodiments of the present application.
Bus 510 includes hardware, software, or both that couple the components of the online data flow billing device to each other. By way of example, and not limitation, the buses may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an infiniband interconnect, a Low Pin Count (LPC) bus, a memory bus, a micro channel architecture (MCa) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a video electronics standards association local (VLB) bus, or other suitable bus, or a combination of two or more of the above. Bus 510 may include one or more buses, where appropriate. Although embodiments of the application have been described and illustrated with respect to a particular bus, the application contemplates any suitable bus or interconnect.
In addition, in combination with the database testing method in the above embodiment, the embodiment of the present application may be implemented by providing a computer storage medium. The computer storage medium has stored thereon computer program instructions; the computer program instructions, when executed by a processor, implement a method of database testing of any of the above embodiments.
In addition, embodiments of the present application also provide a computer program product, wherein instructions in the computer program product, when executed by a processor of an electronic device, enable the electronic device to perform the method of database testing of any of the above embodiments.
It should be understood, however, that the application is not limited to the precise arrangements and instrumentalities shown and described hereinabove. Also, a detailed description of known method techniques is omitted here for the sake of brevity. In the above embodiments, several specific steps are described and shown as examples. The method processes of the present application are not limited to the specific steps described and shown, but various changes, modifications and additions, or the order between steps may be made by those skilled in the art after appreciating the spirit of the present application.
The functional blocks shown in the above-described structural block diagrams may be implemented in hardware, software, firmware, or a combination thereof. When implemented in hardware, it may be, for example, an electronic circuit, an Application Specific Integrated Circuit (ASIC), suitable firmware, a plug-in, a function card, or the like. When implemented in software, the elements of the application are the programs or code segments used to perform the required tasks. The program or code segments may be stored in a machine readable medium or transmitted over transmission media or communication links by a data signal carried in a carrier wave. A "machine-readable medium" may include any medium that can store or transfer information. Examples of machine-readable media include electronic circuitry, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio Frequency (RF) links, and the like. The code segments may be downloaded via computer networks such as the internet, intranets, etc.
It should also be noted that the exemplary embodiments mentioned in this disclosure describe some methods or systems based on a series of steps or devices. The present application is not limited to the order of the above-described steps, that is, the steps may be performed in the order mentioned in the embodiments, or may be performed in a different order from the order in the embodiments, or several steps may be performed simultaneously.
Aspects of the present application are described above with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions/acts specified in the flowchart and/or block diagram block or blocks. Such a processor may be, but is not limited to being, a general purpose processor, a special purpose processor, an application specific processor, or a field programmable logic circuit. It will also be understood that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware which performs the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The present application may be embodied in other specific forms without departing from its spirit or essential characteristics. For example, the algorithms described in particular embodiments may be modified without departing from the basic spirit of the application. The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein.
Those skilled in the art will appreciate that the above-described embodiments are exemplary and not limiting. The different technical features presented in the different embodiments may be combined to advantage. Other variations to the disclosed embodiments can be understood and effected by those skilled in the art in view of the drawings, the description, and the claims. In the claims, the term "comprising" does not exclude other means or steps; the indefinite article "a" does not exclude a plurality; the terms "first," "second," and the like, are used for designating a name and not for indicating any particular order. Any reference signs in the claims shall not be construed as limiting the scope. The functions of the various elements presented in the claims may be implemented by means of a single hardware or software module. The presence of certain features in different dependent claims does not imply that these features cannot be combined to advantage.

Claims (11)

1. A method of database testing, the method comprising:
acquiring a loaded preset structured query language statement through a preset application programming interface, wherein the preset structured query language statement comprises an input parameter type;
instantiating the preset structured query language sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program to obtain a target database operation sentence;
executing the target database operation statement in a target database through a preset application programming interface;
and acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.
2. The method according to claim 1, wherein instantiating the preset structured query language sentence to obtain a target database operation sentence according to the input parameter type and mapping relation information between the input parameter type and an instantiation parameter included in the preset application program, includes:
determining whether the preset structured query language statement is a branch statement according to the target character;
under the condition that the preset structured query language sentence is a branch sentence, obtaining structured query language sentences corresponding to different branches;
based on the input parameter types in the structured query language sentences and the mapping relation information of the input parameter types and the instantiation parameters included in the preset application program, instantiating the preset structured query language sentences to obtain target database operation sentences.
3. The method for testing a database according to claim 1, wherein instantiating the preset structured query language statement to obtain a target database operation statement comprises:
determining a corresponding instantiation object according to an instantiation type corresponding to the preset structured query language statement;
According to a preset instantiation parameter list, determining the parameter type in the instantiation object;
and determining the parameters corresponding to the parameter types as default values, and carrying out object instantiation to obtain a target database operation statement.
4. A method of database testing according to claim 3, wherein after said determining the type of parameter in said instantiated object from a pre-set list of instantiated parameters, said method further comprises:
According to a preset instantiation parameter list, determining a parameter type field value corresponding to a parameter type in the instantiation object;
And constructing a default value of the instantiation object parameter according to the parameter type field value.
5. A method of database testing according to claim 3, wherein the instantiation types include a generic type and a complex type, and said instantiating the object includes:
Traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a common type to obtain a corresponding instantiation field;
and creating a corresponding instantiation object according to the instantiation field.
6. The method of database testing according to claim 5, wherein said creating a corresponding instantiation object further comprises:
traversing the preset structured query language sentence under the condition that the instantiation type corresponding to the preset structured query language sentence is a complex type;
traversing the traversed preset structured query language statement under the condition that the instantiation type corresponding to the traversed preset structured query language statement is of a complex type;
Traversing the preset structured query language sentence to obtain a corresponding instantiation field under the condition that the traversed instantiation type corresponding to the preset structured query language sentence is a common type;
and creating a corresponding instantiation object according to the instantiation field.
7. The method according to any one of claims 1 to 6, wherein after the obtaining the execution result of executing the target database operation sentence in the target database to obtain the test result, the method further comprises:
Determining a problem structured query language statement according to the execution condition in the test result;
And generating a problem statement report through the problem structured query language statement.
8. An apparatus for database testing, the apparatus comprising:
The acquisition module is used for acquiring loaded preset structured query language sentences through a preset application programming interface, wherein the preset structured query language sentences comprise input parameter types;
The instance module is used for instantiating the preset structured query language sentence to obtain a target database operation sentence according to the input parameter type and the mapping relation information of the input parameter type and the instantiation parameter included in the preset application program;
the execution module is used for executing the target database operation statement in a target database through a preset application programming interface;
The acquisition module is further used for acquiring an execution result of executing the target database operation statement in the target database to obtain a test result.
9. An apparatus for database testing, the apparatus comprising: a processor and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the method of database testing as claimed in any one of claims 1 to 7.
10. A computer readable storage medium, having stored thereon computer program instructions which, when executed by a processor, implement a method of database testing according to any of claims 1-7.
11. A computer program product, characterized in that instructions in the computer program product, when executed by a processor of an electronic device, cause the electronic device to perform the method of database testing according to any of claims 1-7.
CN202410132289.6A 2024-01-30 2024-01-30 Method, apparatus, device, and computer-readable storage medium for database testing Pending CN118113681A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410132289.6A CN118113681A (en) 2024-01-30 2024-01-30 Method, apparatus, device, and computer-readable storage medium for database testing

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410132289.6A CN118113681A (en) 2024-01-30 2024-01-30 Method, apparatus, device, and computer-readable storage medium for database testing

Publications (1)

Publication Number Publication Date
CN118113681A true CN118113681A (en) 2024-05-31

Family

ID=91214719

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410132289.6A Pending CN118113681A (en) 2024-01-30 2024-01-30 Method, apparatus, device, and computer-readable storage medium for database testing

Country Status (1)

Country Link
CN (1) CN118113681A (en)

Similar Documents

Publication Publication Date Title
CN110018955B (en) Generating automated test scripts by transforming manual test cases
CN112394942B (en) Distributed software development compiling method and software development platform based on cloud computing
CN113900958A (en) Test case script generation method, system, medium and electronic device
CN109871312B (en) Interface testing method, device, equipment and readable storage medium
CN110990274A (en) Data processing method, device and system for generating test case
CN111949543A (en) Testing method and device based on distributed platform, electronic equipment and storage medium
CN111159016A (en) Standard detection method and device
CN111324510B (en) Log processing method and device and electronic equipment
CN111290961A (en) Interface test management method and device and terminal equipment
CN115118582A (en) Log analysis method and device
CN111159040A (en) Test data generation method, device, equipment and storage medium
CN111767213B (en) Database check point testing method and device, electronic equipment and storage medium
CN112988578A (en) Automatic testing method and device
CN117632710A (en) Method, device, equipment and storage medium for generating test code
CN116775488A (en) Abnormal data determination method, device, equipment, medium and product
CN116466927A (en) Code generation method, system, electronic device and storage medium for batch processing task
CN116737535A (en) Interface test method, device, computer equipment and storage medium
CN118113681A (en) Method, apparatus, device, and computer-readable storage medium for database testing
CN116257223A (en) Data isolation development method, device, equipment, readable storage medium and product
CN115657981A (en) Method for setting print level of print information in authentication environment and authentication method
CN114721943A (en) Method and device for determining test range
CN111639028B (en) Method, device, engine and storage medium for testing account checking rule script
CN113688134A (en) Visual variable management method, system and equipment based on multidimensional data
CN113504904A (en) User-defined function implementation method and device, computer equipment and storage medium
CN115658551B (en) Code testing method, storage medium, electronic device and apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination