Database testing method, device, terminal equipment and storage medium

By segmenting and regular matching of test statements, MongoDB test statements suitable for testing equipment are generated, which solves the problem of insufficient support for MongoDB on the interface platform, reduces learning and maintenance costs, and improves testing efficiency.

CN111309596BActive Publication Date: 2025-08-19CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010059952.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-19
Publication Date
2025-08-19
Estimated Expiration
2040-01-19

AI Technical Summary

Technical Problem

In the prior art, the interface platform lacks support for MongoDB databases, resulting in testers needing to learn additional MongoClient syntax, increasing learning and maintenance costs, and the automated test scenario cannot be effectively executed.

Method used

By obtaining test statements and dividing them into multiple statement segments, matching them with preset regular expressions, obtaining test information, and generating target test statements suitable for the test device, the problem that the test device does not support MongoDB statements is solved.

Benefits of technology

This reduces the learning and maintenance costs of testers and improves testing efficiency, allowing testers to directly use the same syntax as daily operations of MongoDB.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111309596B_ABST
    Figure CN111309596B_ABST
Patent Text Reader

Abstract

The embodiments of the present application are applicable to the field of testing technology and provide a database testing method, apparatus, terminal device, and storage medium. The method comprises: obtaining a test statement for a target database, dividing the test statement into multiple statement segments; performing regular matching on the multiple statement segments using a preset regular expression to obtain test information of the target database, wherein the test information includes test type information; obtaining a target configuration statement that matches the test type information; generating a target test statement based on the test information and the target configuration statement; and testing the target database using the target test statement. This embodiment can use a test statement corresponding to a syntax to implement testing of different types of databases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of testing technology, and in particular relates to a database testing method, apparatus, terminal device, and storage medium. Background Art

[0002] MongoDB is a distributed file storage database with high performance, easy deployment, and ease of use. As MongoDB becomes increasingly popular in the software industry, more and more systems are adopting MongoDB for storage.

[0003] When users conduct interface testing using an interface platform, many test scenarios require database validation. While most interface platforms in the industry offer the ability to execute database statements, support for MongoDB remains limited, or operations against MongoDB can only be performed using the non-native syntax provided by the interface platform. For example, an interface platform requires remote access to a MongoDB database using the non-native MongoClient syntax. Due to differences between MongoDB's native syntax and statements executed by MongoClient, if the interface platform only supports MongoClient syntax, testers not only need to relearn MongoClient syntax, increasing their learning curve, but also need to maintain two sets of database statements, increasing maintenance costs and hindering the rapid iteration requirements of projects. Furthermore, the lack of MongoDB support in the interface platform makes it difficult to effectively verify pre-designed automation scenarios when comparing test interfaces. This can even make it impossible to automate interfaces that rely on database return values as input. Summary of the Invention

[0004] In view of this, embodiments of the present application provide a database testing method, apparatus, terminal device, and storage medium to solve the problem in the prior art that MongoClient cannot be used to execute statements to directly test the MongoDB database.

[0005] A first aspect of an embodiment of the present application provides a database testing method, comprising:

[0006] Obtaining a test statement for a target database, and dividing the test statement into multiple statement segments;

[0007] Using preset regular expressions to perform regular matching on the multiple statement segments respectively to obtain test information of the target database, the test information including test type information;

[0008] Obtaining a target configuration statement that matches the test type information;

[0009] generating a target test statement according to the test information and the target configuration statement;

[0010] The target database is tested using the target test statement.

[0011] A second aspect of an embodiment of the present application provides a database testing device, including:

[0012] A statement segmentation module is used to obtain a test statement for a target database and segment the test statement into multiple statement segments;

[0013] A regular expression matching module, configured to perform regular expression matching on each of the plurality of statement segments using a preset regular expression to obtain test information of the target database, wherein the test information includes test type information;

[0014] A target configuration statement acquisition module is used to acquire a target configuration statement that matches the test type information;

[0015] A target test statement generating module, configured to generate a target test statement according to the test information and the target configuration statement;

[0016] A database testing module is used to test the target database using the target test statement.

[0017] A third aspect of an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the database testing method described in the first aspect when executing the computer program.

[0018] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the database testing method described in the first aspect are implemented.

[0019] Compared with the prior art, the embodiments of the present application have the following advantages:

[0020] In an embodiment of the present application, by obtaining a test statement for a target database, after dividing the test statement into multiple statement segments, a preset regular expression can be used to perform regular matching on the multiple statement segments respectively to obtain the test information of the target database; then, by obtaining a target configuration statement that matches the test type information in the test information, a target test statement can be generated based on the test information and the target configuration statement, so that the test device can use the above target test statement to test the target database. This embodiment uses regular matching to match the test information for executing the test from statements that are only suitable for the database, and then generates an execution statement suitable for the test device based on the above information, which solves the problem that users who use certain types of databases need to relearn the test syntax when using the test device to perform test tasks because the test device does not support the statements of this type of database. When testing, users can directly use the same syntax as the daily operation database to perform the test, which facilitates the test personnel to directly migrate the original statements of the database to the test device, reduces the user's learning cost and maintenance cost, and improves the test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] To more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can derive other drawings based on these drawings without inventive effort.

[0022] Figure 1 This is a schematic diagram of the steps of a database testing method according to an embodiment of the present application;

[0023] Figure 2 This is a flowchart of another database testing method according to an embodiment of the present application;

[0024] Figure 3 is a schematic diagram of a database testing device according to an embodiment of the present application;

[0025] Figure 4 This is a schematic diagram of a terminal device according to an embodiment of the present application. DETAILED DESCRIPTION

[0026] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obstructing the description of the present application with unnecessary details.

[0027] The technical solution of this application is described below through specific embodiments.

[0028] Reference Figure 1 , shows a schematic flow chart of the steps of a database testing method according to an embodiment of the present application, which may specifically include the following steps:

[0029] S101, obtaining a test statement for a target database, and dividing the test statement into multiple statement segments;

[0030] It should be noted that this method can be applicable to a terminal device, which can be a device or tool capable of testing a database.

[0031] Typically, database testing is performed using test statements. After establishing a communication connection between the test device and the database, the test device sends one or more test statements to the database to verify that the database has certain functions or to check whether the database's performance is stable.

[0032] Typically, the test statements provided by the test equipment are written in a programming language. If the database to be tested is also developed in that language, the test statements can be written directly in the same language. However, if the programming language used to develop the database differs from the language used by the test equipment, the database cannot be tested directly using the test statements provided by the test equipment. The statements applicable to the database must be converted into statements that the test equipment can understand to facilitate accurate execution by the interface testing tool. This embodiment obtains test statements applicable to the database and, through a series of processing steps, converts them into target test statements applicable to the test equipment.

[0033] Therefore, the test statements for the target database can be written in the programming language used when developing the target database. If the programming language used for the test is different from the programming language used by the database, such test statements cannot be used directly in the test equipment.

[0034] In this embodiment, the test statement can be input by a tester through the front-end interface of the test device. After obtaining the test statement, the test device can divide the statement into multiple sentence segments according to certain rules.

[0035] In a specific implementation, statements can be segmented based on the syntax used by the test statement. For example, some programming languages use a dot separator (.) to separate different parts of a statement, while other programming languages may use spaces to separate different parts of the same statement. Therefore, when segmenting test statements, you can use either a dot separator or a space to complete the division of statement segments.

[0036] Alternatively, a method similar to word segmentation may be used to identify each English word or phrase in the test sentence and segment the test sentence into multiple sentence segments, which is not limited in this embodiment.

[0037] S102: using a preset regular expression to perform regular matching on the multiple statement segments respectively to obtain test information of the target database, the test information including test type information;

[0038] The preset regular expression may be an expression that matches the programming language used by the database, that is, by matching the regular expression, the specific content of each statement segment in the test statement may be identified.

[0039] Typically, regular expressions are different for different programming languages. Therefore, if you want to use the same test equipment to test databases using multiple different programming languages, you need to write a corresponding regular expression for each programming language.

[0040] In a specific implementation, when regular expressions are used to perform regular matching on test statements, each statement segment can be matched and identified one by one, and the identified content is the test information carried in the test statement.

[0041] For example, by performing regular expression matching on each statement segment of a test statement, corresponding data table information, test type information, test object information, and so on can be obtained.

[0042] The above-mentioned data table information may refer to which table in the database needs to be tested, the test type information indicates which test method should be used for testing, and the test object information may specifically indicate which field in the data table needs to be tested.

[0043] Of course, depending on actual needs, the test information obtained through regular matching can also include other information, such as test time information, etc.

[0044] S103, obtaining a target configuration statement that matches the test type information;

[0045] In this embodiment, a plurality of configuration languages may be pre-written according to the programming language used by the test device, and each configuration language may represent a specific test method or test type.

[0046] Typically, database test statements include not only the specific test content that the test equipment understands, but also some database parameter information. Therefore, when writing the configuration language, you can predetermine the test types that the test equipment can perform, then write configuration statements for each type, replacing the parameters used to write to the database with template language.

[0047] After obtaining the test type information through regular matching, you can directly find the target configuration statement that matches the type from the pre-written configuration statements.

[0048] For example, for a test type of find, multiple configuration languages can be traversed to extract configuration statements belonging to the find type.

[0049] S104, generating a target test statement according to the test information and the target configuration statement;

[0050] After matching the test information and finding the target configuration statement of the corresponding type, the target test statement can be generated using the above information. The target test statement can be written in a programming language suitable for use in the test equipment.

[0051] S105: Use the target test statement to test the target database.

[0052] It should be noted that before formally using the target test statement to test the target database, the test device may also check the generated target test statement to determine whether the statement complies with corresponding grammatical rules.

[0053] If the target test statement does not conform to the grammatical rules of the test device, a prompt message can be generated and fed back to the front-end interface of the test device, and the execution phase will not be entered, thus avoiding unnecessary database resource operations.

[0054] In an embodiment of the present application, by obtaining a test statement for the target database, after dividing the test statement into multiple statement segments, a preset regular expression can be used to perform regular matching on the multiple statement segments respectively to obtain the test information of the target database; then, by obtaining a target configuration statement that matches the test type information in the test information, a target test statement can be generated based on the test information and the target configuration statement, so that the test device can use the above target test statement to test the target database. This embodiment uses regular matching to match test information for executing tests from statements that are only suitable for databases, and then generates execution statements suitable for the test device based on the above information. This solves the problem that users who use certain types of databases need to relearn the test syntax when using the test device to perform test tasks because the test device does not support the statements of this type of database. When testing, users can directly use the same syntax as the daily operation database to perform tests, which facilitates testers to directly migrate the original statements of the database to the test device, reducing the user's learning cost and maintenance cost and improving test efficiency.

[0055] Reference Figure 2 , shows a schematic flow chart of another database testing method according to an embodiment of the present application, which may specifically include the following steps:

[0056] S201: Obtain a test statement for a target database, identify a delimiter contained in the test statement, and divide the test statement into multiple statement segments according to the delimiter;

[0057] It should be noted that this method can be applied to a test device. That is, the test device processes the test statement input by the tester to generate a target test statement that can be directly executed by the test device, so that the test device can use the target test statement to complete the test of the database.

[0058] For ease of understanding, this embodiment is described below by taking the target database as a MongoDB database and the execution statement used by the test device as a MongoClient statement written based on MongoClient syntax as an example.

[0059] Therefore, the test statements for the target database can refer to MongoDB execution statements for testing the MongoDB database. Due to certain differences between the MongoClient syntax and the MongoDB syntax used by the MongoDB database, when using a test device based on the MongoClient syntax for testing, it is necessary to convert the MongoDB statements into MongoClient statements to facilitate accurate execution of the test device.

[0060] In this embodiment, the MongoDB statement can be input by the tester through the front-end interface of the test device. For example, db.getCollection('abc').find({"sname":"sun"})

[0061] Of course, before entering the above MongoDB statement, the tester also needs to select the database type and database address to be executed through the front-end interface.

[0062] After receiving the MongoDB statement, the test device can split it into multiple segments according to preset rules. It can then convert and concatenate the segments to generate the target test statement that conforms to the MongoClient syntax.

[0063] Due to the characteristics of MongoDB syntax, in specific implementations, MongoDB statements can be split into multiple statement segments using dot separators (.).

[0064] For example, for the above example, three different statement segments can be obtained after splitting by dot separators:

[0065] db;

[0066] getCollection('abc'); and,

[0067] find({"sname":"sun"}).

[0068] S202: for any target sentence segment among the multiple sentence segments, identifying whether the target sentence segment is the sentence header of the test sentence;

[0069] Typically, a MongoDB statement used to execute a database test consists of multiple parts, such as a statement header, a data table execution statement, and a test information execution statement.

[0070] In the above example, db is the statement header, getCollection('abc') is the data table execution statement, and find({"sname":"sun"}) is the test information execution statement.

[0071] The statement header is only used to indicate the syntax applicable to the statement and has no other specific meaning.

[0072] Therefore, for any target sentence segment among the multiple sentence segments obtained after segmentation, it is possible to first identify whether the target sentence segment is a sentence header in the test sentence. The target sentence segment is any sentence segment currently being identified. If so, the sentence header can be directly discarded; if a sentence segment does not belong to a sentence header, step S203 can be continued to perform regular matching on the target sentence segment with multiple preset regular expressions one by one.

[0073] S203, performing regular matching on the target sentence segment with a plurality of preset regular expressions one by one;

[0074] Typically, regular expressions are different for different programming languages, so you can write a regular expression for each programming language your database is designed for.

[0075] For each sentence segment in the test sentence, each sentence segment can be matched and identified one by one, and the identified content is the test information carried in the test sentence.

[0076] The regular expression matching method used in this embodiment may be a match() method, which can search for a specified value in a string, or find a match for one or more regular expressions.

[0077] According to programming rules, all MongoDB statements begin with "db". Therefore, if the statement segment is "db", you do not need to perform a match on it.

[0078] S204: When the target statement segment matches any regular expression, obtain test information corresponding to the currently matched regular expression, and use the test information corresponding to the currently matched regular expression as test information of the target database, wherein the test information includes test type information;

[0079] In this embodiment, if a certain statement segment is matched and a positive expression is hit, the test information corresponding to the expression can be directly extracted.

[0080] For example, after using the match() method to identify the segmented statement segments, it can be determined that the name of the data table currently executing the test is "abc", and the corresponding test information is find({"sname":"sun"}).

[0081] It should be noted that the test type information written into the MongoDB statement generally includes the specific type and specific test object when executing the test. Therefore, when identifying the test type information, multiple matching processes can be performed.

[0082] In the specific implementation, when the target statement segment hits the preset test type expression, the test type information corresponding to the test type expression can be directly obtained, and then the preset test object expression is used to perform regular matching on the target statement segment again to obtain the test object information corresponding to the test object expression.

[0083] Of course, the process of using the test object expression to perform regular matching on the target statement segment may include multiple times, so as to identify multiple test objects in the original test statement.

[0084] In the above example, after two matches, the test type of the executed test is find, and the corresponding test object is {"sname":"sun"}.

[0085] S205: Acquire a target configuration statement that matches the test type information;

[0086] In this embodiment, for different test types, corresponding configuration statements can be pre-written for each test type using MongoClient syntax.

[0087] Typically, database test statements include not only the specific test content that the test equipment understands, but also some database parameter information. Therefore, when writing the configuration language, you can predetermine the test types that the test equipment can perform, then write configuration statements for each type, replacing the parameters used to write to the database with template language.

[0088] For example, for the find test type, the corresponding MongoClient configuration statement can be expressed as:

[0089] dbo.collection(databaseName).find(optionStr).toArray(function(err,result)).

[0090] S206, using the data table information, the test type information, and the test object information as parameters, passing the parameters into the target configuration statement to generate a target test statement;

[0091] In this embodiment, the data table information, test type information, and test object information obtained in step S204 can be passed as parameters to the target configuration statement obtained in step S205 to generate a MongoClient execution statement for executing the test on the MongoDB database.

[0092] In a specific implementation, the position of each parameter in the target configuration statement can be first identified, and then the data table information, test type information and test object information obtained above are written into the corresponding positions in the target configuration statement to generate a target test statement.

[0093] S207: Use the target test statement to test the target database.

[0094] After converting MongoDB test statements written in MongoDB syntax into MongoClient target test statements written in MongoClient syntax, the test tool can use the target test statements to test the MongoDB database.

[0095] The embodiment of the present application uses regular expression matching to match the data table, test type, and test object information used to execute the test from the MongoDB statement, and then generates a MongoClient execution statement based on the above information. This solves the problem that users who use the MongoDB database need to relearn the MongoClient syntax when using the test equipment to perform test tasks because the test equipment does not support MongoDB statements. When testing, users can directly use the same MongoDB syntax as in daily database operations, which makes it convenient for testers to directly migrate MongoDB native statements to the test equipment, reducing users' learning and maintenance costs.

[0096] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0097] Reference Figure 3 , shows a schematic diagram of a database testing device according to an embodiment of the present application, which may specifically include the following modules:

[0098] The statement segmentation module 301 is used to obtain a test statement for a target database and segment the test statement into multiple statement segments;

[0099] A regular expression matching module 302 is configured to perform regular expression matching on each of the plurality of statement segments using a preset regular expression to obtain test information of the target database, wherein the test information includes test type information;

[0100] A target configuration statement acquisition module 303 is configured to acquire a target configuration statement that matches the test type information;

[0101] A target test statement generating module 304 is configured to generate a target test statement based on the test information and the target configuration statement;

[0102] The database testing module 305 is configured to test the target database using the target test statement.

[0103] In the embodiment of the present application, the sentence segmentation module 301 may specifically include the following submodules:

[0104] A delimiter identification submodule is used to obtain a test statement for a target database and identify the delimiters contained in the test statement;

[0105] The sentence segmentation submodule is used to segment the test sentence into multiple sentence segments according to the separator.

[0106] In the embodiment of the present application, the regular matching module 302 may specifically include the following submodules:

[0107] a sentence header identification submodule, configured to identify, for any target sentence segment among the plurality of sentence segments, whether the target sentence segment is a sentence header of the test sentence;

[0108] A regular matching submodule is used to perform regular matching on the target sentence segment with multiple preset regular expressions one by one if no;

[0109] The test information acquisition submodule is used to obtain the test information corresponding to the regular expression currently hit when the target sentence segment hits any regular expression, and use the test information corresponding to the regular expression currently hit as the test information of the target database.

[0110] In the embodiment of the present application, the regular expression may include a test type expression and a test object expression, and the test information acquisition submodule may specifically include the following units:

[0111] a test type information acquisition unit, configured to acquire test type information corresponding to a preset test type expression when the target statement segment hits the preset test type expression;

[0112] The test object information acquisition unit is used to use a preset test object expression to perform regular expression matching on the target statement segment again to obtain the test object information corresponding to the test object expression.

[0113] In the embodiment of the present application, the test information may further include data table information, and the target test statement generation module 304 may specifically include the following submodules:

[0114] The target test statement generation submodule is used to take the data table information, the test type information and the test object information as parameters, pass the parameters into the target configuration statement, and generate a target test statement.

[0115] In an embodiment of the present application, the target test statement generation submodule may specifically include the following units:

[0116] a parameter position identification unit, configured to identify the position of each parameter in the target configuration statement;

[0117] The test information writing unit is used to write the data table information, the test type information and the test object information into corresponding positions in the target configuration statement respectively to generate a target test statement.

[0118] In an embodiment of the present application, the target database may be a MongoDB database, the test statement may be a MongoDB execution statement for testing the MongoDB database, and the target test statement may be a MongoClient execution statement for testing the MongoDB database.

[0119] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.

[0120] Reference Figure 4 , shows a schematic diagram of a terminal device according to an embodiment of the present application. Figure 4 As shown, the terminal device 400 of this embodiment includes: a processor 410, a memory 420, and a computer program 421 stored in the memory 420 and executable on the processor 410. When the processor 410 executes the computer program 421, the steps in each embodiment of the above-mentioned database testing method are implemented, such as Figure 1 Alternatively, when the processor 410 executes the computer program 421, the functions of the modules / units in the above-mentioned device embodiments are realized, for example, Figure 3 Functions of modules 301 to 305 are shown.

[0121] Exemplarily, the computer program 421 can be divided into one or more modules / units, which are stored in the memory 420 and executed by the processor 410 to complete the present application. The one or more modules / units can be a series of computer program instruction segments that can perform specific functions, and the instruction segments can be used to describe the execution process of the computer program 421 in the terminal device 400. For example, the computer program 421 can be divided into a statement segmentation module, a regular matching module, a target configuration statement acquisition module, a target test statement generation module, and a database test module. The specific functions of each module are as follows:

[0122] A statement segmentation module is used to obtain a test statement for a target database and segment the test statement into multiple statement segments;

[0123] A regular expression matching module, configured to perform regular expression matching on each of the plurality of statement segments using a preset regular expression to obtain test information of the target database, wherein the test information includes test type information;

[0124] A target configuration statement acquisition module is used to acquire a target configuration statement that matches the test type information;

[0125] A target test statement generating module, configured to generate a target test statement according to the test information and the target configuration statement;

[0126] A database testing module is used to test the target database using the target test statement.

[0127] The terminal device 400 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device 400 may include, but is not limited to, a processor 410 and a memory 420. Those skilled in the art will understand that Figure 4 It is only an example of the terminal device 400 and does not constitute a limitation of the terminal device 400. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device 400 may also include input and output devices, network access devices, buses, etc.

[0128] The processor 410 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0129] The memory 420 may be an internal storage unit of the terminal device 400, such as a hard disk or memory of the terminal device 400. The memory 420 may also be an external storage device of the terminal device 400, such as a plug-in hard disk equipped on the terminal device 400, a smart memory card (SMC), a secure digital (SD) card, a flash card, etc. Furthermore, the memory 420 may include both an internal storage unit of the terminal device 400 and an external storage device. The memory 420 is used to store the computer program 421 and other programs and data required by the terminal device 400. The memory 420 may also be used to temporarily store data that has been output or is about to be output.

[0130] The above embodiments are intended only to illustrate the technical solutions of the present application and are not intended to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they may still modify the technical solutions described in the above embodiments or replace some of the technical features therein with equivalents; and such modifications or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application and should be included within the scope of protection of the present application.

Claims

1. A database testing method, characterized in that: include: Obtaining a test statement for a target database, and dividing the test statement into multiple statement segments according to grammatical rules used by the test statement; Performing regular matching on the multiple statement segments using a preset regular expression to obtain test information of the target database, the test information including data table information, test type information, and test object information, the preset regular expression being an expression that matches the programming language used by the target database; Obtaining a target configuration statement that matches the test type information; generating a target test statement according to the test information and the target configuration statement; Testing the target database using the target test statement; The method of using a preset regular expression to perform regular matching on the multiple statement segments to obtain the test information of the target database includes: For any target sentence segment among the multiple sentence segments, identifying whether the target sentence segment is a sentence header of the test sentence; If not, the target sentence segment is matched against multiple preset regular expressions one by one; When the target sentence segment hits any regular expression, the test information corresponding to the currently hit regular expression is obtained, and the test information corresponding to the currently hit regular expression is used as the test information of the target database.

2. The method according to claim 1, characterized in that The step of obtaining a test statement for a target database and dividing the test statement into multiple statement segments includes: Obtaining a test statement for a target database, and identifying a delimiter contained in the test statement; The test statement is divided into multiple statement segments according to the separator.

3. The method according to claim 1, characterized in that The regular expression includes a test type expression and a test object expression. When the target statement segment hits any regular expression, the test information corresponding to the currently hit regular expression is obtained, including: When the target statement segment hits a preset test type expression, obtaining test type information corresponding to the test type expression; The target sentence segment is again matched with a preset test object expression to obtain the test object information corresponding to the test object expression.

4. The method according to claim 3, characterized in that The test information also includes data table information. Generating a target test statement based on the test information and the target configuration statement includes: The data table information, the test type information and the test object information are used as parameters, and the parameters are passed into the target configuration statement to generate a target test statement.

5. The method according to claim 4, characterized in that The step of taking the data table information, the test type information, and the test object information as parameters, passing the parameters into the target configuration statement, and generating a target test statement includes: Identify the position of each parameter in the target configuration statement; The data table information, the test type information, and the test object information are respectively written into corresponding positions in the target configuration statement to generate a target test statement.

6. The method according to claim 1, characterized in that The target database is a MongoDB database, the test statement is a MongoDB execution statement for testing the MongoDB database, and the target test statement is a MongoClient execution statement for testing the MongoDB database.

7. A database testing device, characterized in that: include: A statement segmentation module is used to obtain a test statement for a target database and segment the test statement into multiple statement segments according to the grammatical rules used by the test statement; a regular expression matching module, configured to perform regular expression matching on each of the plurality of statement segments using a preset regular expression to obtain test information of the target database, the test information including data table information, test type information, and test object information, wherein the preset regular expression is an expression matching the programming language used by the target database; A target configuration statement acquisition module is used to acquire a target configuration statement that matches the test type information; A target test statement generating module, configured to generate a target test statement according to the test information and the target configuration statement; A database testing module, configured to test the target database using the target test statement; The regular matching module specifically includes the following submodules: a sentence header identification submodule, configured to identify, for any target sentence segment among the plurality of sentence segments, whether the target sentence segment is a sentence header of the test sentence; A regular matching submodule is used to perform regular matching on the target sentence segment with multiple preset regular expressions one by one if no; The test information acquisition submodule is used to obtain the test information corresponding to the regular expression currently hit when the target sentence segment hits any regular expression, and use the test information corresponding to the regular expression currently hit as the test information of the target database.

8. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the database testing method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the database testing method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Statement conversion method and system between databases and, terminal

    CN109857757A

  • Database testing method and device and computer equipment

    CN110147319A