Test case generation method and device, equipment, medium and product
By abstracting the database object and generating temporary statements, the problem of low generation efficiency of test cases in the existing technology in complex testing scenarios is solved, and the applicability and generation efficiency of database test cases are improved.
Patent Information
- Application Number
- CN202411322648.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2025-01-10
AI Technical Summary
Existing database test case generation schemes are difficult to apply in complex testing scenarios, especially when multi-step operations and multiple objects are called with each other, the efficiency and reliability of test case generation and maintenance are low.
By abstracting the actual objects in the database to be tested, object information of type objects is generated, and temporary statements with different attributes under each operation method are generated based on the object information, temporary object identifiers are replaced to generate test cases, and test cases are improved in complex scenarios applicability under.
It improves the applicability and generation efficiency of database test cases in complex testing scenarios, and enhances the logic and code executability of statements.
Smart Images

Figure CN119292918A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database testing, and in particular to a test case generation method, device, equipment, medium and product. Background Art
[0002] Databases are systems used to store, manage, and retrieve data, and are widely used in various software and applications. They organize data in a structured way, making data access and manipulation more efficient and reliable. In order to ensure that the database can correctly perform its intended functions, database functional testing is particularly important. Database functional testing includes verifying whether data insertion, update, deletion, and query operations work as expected, thereby ensuring the accuracy and reliability of the database system.
[0003] In the existing test case generation scheme for data functional testing, a single database test statement is usually generated for simple operations on database objects. However, this scheme lacks consideration of multi-step operations under complex business logic and is difficult to apply to database functional testing in complex scenarios. Therefore, the current problem that needs to be solved is how to improve the applicability of database test cases in complex test scenarios. Summary of the invention
[0004] The present application provides a test case generation method, apparatus, device, medium and product to improve the applicability of database test cases in complex test scenarios.
[0005] On the one hand, the present application provides a test case generation method, including: abstracting actual objects in a database to be tested to obtain object information of a type object; wherein different type objects represent different types; the object information includes attributes, operation methods and relationship information; based on the object information, generating temporary statements corresponding to different attributes of the type object under each operation method; based on the object to be tested in the test requirements of the database to be tested, replacing the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object, and flushing the statements obtained after each replacement into an SQL file to obtain a test case set; wherein the test case set includes statements corresponding to each object to be tested under each operation method.
[0006] In a possible implementation, according to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, including: determining a unified object identifier under each type according to the type of the object to be tested; replacing the temporary object identifier in the temporary statement with a unified object identifier of the same type as the type of the type object, and obtaining a unified statement corresponding to different attributes of the type object under each operation method; replacing the unified object identifier in the unified statement with the object identifier of each object to be tested under the type corresponding to the unified object identifier.
[0007] In a possible implementation, before generating temporary statements corresponding to different attributes of the type object under each operation method according to object information, it also includes: determining a generation priority of the temporary statements of the type object; generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information, including: generating temporary statements corresponding to different attributes of the type object under each operation method according to the generation priority and the object information.
[0008] In a possible implementation, determining a generation priority of a temporary statement of a type object includes: determining a generation priority of a temporary statement of the type object according to relationship information under object information of the type object; if the type object has a combination relationship with other type objects, setting a generation priority of temporary statements of the type object and other type objects to high; wherein the priority of the included type object is higher than the priority of the included type object; if the type object has a dependency relationship with other type objects, setting a generation priority of temporary statements of the type object and other type objects to medium; wherein the priority of the dependent type object is higher than the priority of the dependent type object; if the type object has an association relationship with other type objects, setting a generation priority of temporary statements of the type object and other type objects to low.
[0009] In a possible implementation, determining a generation priority of a temporary statement of a type object includes: for the same type of object, different operation methods of the type of object have different generation priorities of temporary statements; wherein the priorities are from high to low: create operation, alter operation, insert operation, update operation, select operation.
[0010] In one possible implementation, temporary statements corresponding to different attributes of the type object under each operation method are generated based on object information, including: generating temporary statements corresponding to different attributes of the type object under each operation method based on grammatical rules corresponding to different attributes of the type object under each operation method.
[0011] On the other hand, the present application provides a test case generation device, including: an abstract module, used to abstract the actual objects in the database to be tested to obtain object information of the type object; wherein different type objects represent different types; the object information includes attributes, operation methods and relationship information; a generation module, used to generate temporary statements corresponding to different attributes of the type object under each operation method according to the object information; a replacement module, used to replace the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object according to the object to be tested in the test requirements of the database to be tested, and flush the statement obtained after each replacement into an SQL file to obtain a test case set; wherein the test case set includes the statements corresponding to each object to be tested under each operation method.
[0012] On the other hand, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the above method.
[0013] On the other hand, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the above method.
[0014] On the other hand, the present application provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0015] The test case generation method, device, equipment, medium and product provided by the present application include: abstracting the actual objects in the database to be tested to obtain the object information of the type object; generating temporary statements corresponding to different attributes of the type object under each operation method according to the object to be tested in the test requirements of the database to be tested; replacing the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object according to the object to be tested in the test requirements of the database to be tested, and writing the statement obtained after each replacement into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute, and the test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0017] Figure 1 A flow chart of a test case generation method is exemplarily shown in FIG.
[0018] Figure 2 A type of object model diagram is exemplarily shown in FIG.
[0019] Figure 3 A flow chart of a test case generation method is exemplarily shown in FIG.
[0020] Figure 4 A flow chart of a test case generation method is exemplarily shown in FIG.
[0021] Figure 5 A flow chart of a test case generation method is exemplarily shown in FIG.
[0022] Figure 6 A flow chart of a test case generation method is exemplarily shown in FIG.
[0023] Figure 7 A structural schematic diagram of a test case generating device is exemplarily shown in FIG.
[0024] Figure 8 A structural schematic diagram of an electronic device is shown in FIG.
[0025] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0026] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0027] It should be noted that the brief description of the terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of the present application. Unless otherwise specified, these terms should be understood according to their common and usual meanings. The terms "including" and "having" in the specification and claims and the above-mentioned drawings in this application and any variation thereof are intended to cover but not exclude inclusion. For example, a product or device containing a series of components is not necessarily limited to those components clearly listed, but may include other components that are not clearly listed or inherent to these products or devices. The term "module" used in this application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or a combination of hardware and / or software code that can perform functions related to the element.
[0028] With the development of the Internet, the demand for databases is getting higher and higher, mainly manifested in the need to process large-scale data, support real-time data analysis, manage diverse data types, and deeply integrate with artificial intelligence and machine learning. Among them, a database is a systematic collection of data, and its core components include tables, indexes, views, and transactions. Databases are usually managed by database management systems, which provide a series of tools and functions to define, create, query, update, and manage data.
[0029] In order to ensure that the database can operate normally and meet business needs, it is necessary to generate test cases to perform functional testing on the database. Database functional testing mainly verifies various functions of the database, including operations such as data insertion, update, deletion, and query, to ensure that these functions can be executed correctly under various conditions. In the existing test case generation scheme for data functional testing, a single database test statement is usually generated for simple operations on a single object in the database. For example, for the creation, query, and update of a table, corresponding creation, query, and update statements are generated. However, when there are test requirements in complex test scenarios, such as the need to generate test statements with fixed conditions, multiple test steps, and multiple objects calling each other, the efficiency and reliability of the test case generation and maintenance of this scheme are low. Therefore, the current problem that needs to be solved is how to improve the applicability of database test cases in complex test scenarios.
[0030] The technical content provided by the present application is intended to solve the above-mentioned technical problems of related technologies. The test case generation method, device, equipment, medium and product provided by the present application include: abstracting the actual objects in the database to be tested to obtain the object information of the type object; generating temporary statements corresponding to different attributes of the type object under each operation method according to the object to be tested in the test requirements of the database to be tested; replacing the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object according to the object to be tested in the test requirements of the database to be tested, and flushing the statement obtained after each replacement into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute. The test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios.
[0031] The technical solutions of the present application and the technical solutions of the present application are described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. In the description of the present application, unless otherwise clearly specified and limited, each term should be understood in a broad sense in the art. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0032] Embodiment 1
[0033] Figure 1 A flow chart of a test case generation method is shown in FIG. 1 . The execution subject of this example may be a test case generation device, such as Figure 1 As shown, the method includes:
[0034] Step 101: abstract the actual objects in the database to be tested to obtain object information of type objects; different type objects represent different types; the object information includes attributes, operation methods and relationship information;
[0035] Step 102: Generate temporary statements corresponding to different attributes of the type object under each operation method according to the object information;
[0036] Step 103: According to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is flushed into the SQL file to obtain a test case set; wherein the test case set includes the statements corresponding to each object to be tested under each operation method.
[0037] In practical applications, the executor of the method can be a test case generating device, and there are many ways to implement it. For example, it can be implemented through a computer program, such as application software, etc.; or, it can be implemented as a medium storing relevant computer programs, such as a USB flash drive, a cloud disk, etc.; or, it can be implemented through a physical device integrated or installed with relevant computer programs, such as a chip, etc.
[0038] Exemplarily, the actual objects in the database to be tested can be abstracted by modeling to obtain the object information of the type object. In practical applications, the modeling process can be implemented by modeling languages such as Unified Modeling Language (UML) or Systems Modeling Language (SysML). Among them, the actual objects in the database to be tested refer to the objects in the data structure of the database to be tested that have been stored. The actual objects may include all the objects in the database to be tested, or the selected objects to be tested. For example, the actual objects may include any of the following: tables, fields, functions, stored procedures, packages, views, synonyms, and triggers. Accordingly, the actual objects are abstracted to obtain the type objects; for example, there are two actual objects, Table A and Table B, in the database, and the corresponding type objects are all table type objects. The object information of the type object may include attributes such as common attributes, partition attributes, integration attributes, local attributes, and global attributes, operation methods such as create operations, modify operations, update operations, and delete operations, and relationship information such as the combination relationship, association relationship, dependency relationship, and inheritance relationship between objects. The object information of the type object includes the attributes, operation methods and associations of the actual object; for example, the attributes under the object information of the table type object include two attribute information: the global attributes of the actual object table A and the local attributes of the actual object table B. For example, taking the example of obtaining a modeling model including the type object by modeling, the following can be obtained: Figure 2 An example of a type of object model diagram is shown below. Figure 2 The type object model shown includes: attribute sub-model, operation method sub-model, relationship information sub-model. In actual application, in the type object model, a mapping relationship between the type object and the object information under each sub-model can be established according to the same type object.
[0039] After obtaining the object information of the type object, a temporary statement corresponding to different attributes of the type object under each operation method is generated according to the object information. Exemplarily, obtaining the type object and the object information of the type object, generating a temporary statement can be executed in advance and the temporary statement can be stored, and the stored temporary statement can be called after receiving the test requirements. In this example, the temporary statement is generated based on two dimensions, namely the operation method of the type object and the attribute of the type object. In actual applications, the attributes and operation methods in the object information of each type object are traversed and combined, and a temporary statement is generated based on the combined attributes and operation methods. For example, for a table type object, a temporary statement corresponding to the creation of a global table can be generated; optionally, the temporary statement can also represent statements that call each other between multiple type objects, such as for a function type object, a temporary statement is created that can call a global function of a global table.
[0040] After obtaining the temporary statement corresponding to the type object, according to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is written into the structured query language (SQL) file to obtain a test case set; wherein the test case set includes the corresponding statements of each object to be tested under each operation method. In this example, the object to be tested is also an actual object existing in the database to be tested. In practical applications, the test requirements can be the case where function A operates view B, and view B operates table C at the same time. According to the type objects of the three objects, the temporary statements of the corresponding operations and corresponding attributes are matched, and the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object. It should be noted that the object name created by the temporary statement when it is generated may be random, and the names of the same object may be different in the temporary statements of different types of objects operating the same type of object. Therefore, the logic and code executableness of the generated statements can be enhanced by replacing the identifier. Exemplarily, the test requirement of the same test may include statements after identifier replacement corresponding to multiple operation methods, and the multiple statements are flushed into the SQL file as a test case set corresponding to the test requirement.
[0041] In the test case generation method provided by the present application, the actual objects in the database to be tested are abstracted to obtain the object information of the type object; based on the object information, temporary statements corresponding to different attributes of the type object under each operation method are generated; based on the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is written into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute, and the test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios.
[0042] In practical applications, the randomness and complexity of temporary identifiers of temporary statements may lead to low test case generation efficiency. As another example, Figure 3 A flow chart of a test case generation method is shown in FIG. Figure 3 As shown, in step 103, according to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, including:
[0043] Step 201: Determine a unified object identifier for each type according to the type of the object to be tested;
[0044] Step 202: Replace the temporary object identifier in the temporary statement with a unified object identifier of the same type as the type object, and obtain a unified statement corresponding to different attributes of the type object under each operation method;
[0045] Step 203: Replace the unified object identifier in the unified statement with the object identifier of each object to be tested under the type corresponding to the unified object identifier.
[0046] In this example, in the statement dimension, the temporary object identifier in the temporary statement corresponding to the type object is replaced with a unified object identifier of the same type as the type of the type object, and a unified statement corresponding to different attributes of the type object under each operation method is obtained, and then the unified object identifier in the unified statement is replaced with the object identifier of each object to be tested under the type corresponding to the unified object identifier. For example, the identifier of the same type of object in the temporary statements of different type objects is random and inconsistent because it is temporarily generated. The solution of this example can improve the readability and consistency of different temporary statements by replacing them with a unified object identifier, and improve the continuity of the test in the subsequent test case execution stage. At the same time, replacing the object identifier of the object to be tested with the object identifier of the object to be tested can realize the test of the object to be tested.
[0047] As another example, Figure 4A flow chart of a test case generation method is shown in FIG. Figure 4 As shown, before generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information in step 102, it also includes:
[0048] Step 301, determining the generation priority of temporary statements of type objects;
[0049] In step 102, temporary statements corresponding to different attributes of the type object under each operation method are generated according to the object information, including:
[0050] Step 302: Generate temporary statements corresponding to different attributes of the type object under each operation method according to the generation priority and object information.
[0051] In actual applications, the priority of temporary statement generation of type objects can be fixed, or determined according to the number of actual objects under the type object. For example, the more actual objects there are in the database to be tested, the higher the priority of temporary statement generation of the corresponding type object. Optionally, the priority of the type object can also be determined according to the logical sequence of the operation methods of the type object under the object information. Optionally, the priority of temporary statement generation of the type object can also be determined according to the attributes of the type object under the object information, such as according to the scope of the type object, such as the priority of the type object of global attributes is higher than the priority of the type object of local attributes. The scheme of this example generates temporary statements corresponding to different attributes of the type object under each operation method according to the generation priority and object information, which can improve the flexibility of temporary statement generation of the type object.
[0052] As another example, Figure 5 A flow chart of a test case generation method is shown in FIG. Figure 5 As shown, determining the generation priority of temporary statements of type objects in step 301 includes:
[0053] Step 401, determining the generation priority of temporary statements of the type object according to the relationship information under the object information of the type object;
[0054] Step 402: If the type object has a combination relationship with other type objects, the priority of temporary statement generation between the type object and other type objects is set to high; wherein the priority of the included type object is higher than the priority of the included type object;
[0055] Step 403: If the type object has a dependency relationship with other type objects, the priority of temporary statement generation between the type object and other type objects is set to medium; wherein the priority of the dependent type object is higher than the priority of the dependent type object;
[0056] Step 404: If the type object has an association relationship with other type objects, the temporary statement generation priority between the type object and other type objects is set to low.
[0057] The solution of this example determines the priority of generating temporary statements of type objects based on the logical relationship between different type objects. The combination relationship means that one type object contains another type object. For example, a table and a field: a table is composed of multiple fields. The priority of the contained type object, i.e., the field, is higher than the priority of the contained type object, i.e., the table.
[0058] Dependency means that the existence of one type object depends on another type object. For example: view and table: view is created based on table, so view depends on table; stored procedure and table: SQL statement in stored procedure may reference table, so stored procedure depends on these tables; trigger and table: trigger is triggered based on table event, so trigger depends on table. Among them, the priority of the dependent type object, i.e. table, is higher than the priority of the contained type object, i.e. view.
[0059] An association relationship refers to objects being related to each other in some way. For example, tables are related through foreign keys, where a foreign key in one table references the primary key of another table; indexes and tables: indexes are created based on table columns, and although indexes do not depend on the existence of tables, there is an association between them; synonyms and original objects: synonyms are references to original objects for easy access. Since there is no strict logical precedence between the two types of objects in an association relationship, the internal priority of the two objects may not be specified.
[0060] The solution of this example can improve the logic of temporary statement generation by determining the generation priority of temporary statements of type objects according to the relationship information under the object information of the type objects.
[0061] As another example, determining the generation priority of temporary statements of type objects in step 301 includes:
[0062] For the same type of object, the generation priority of temporary statements corresponding to different operation methods of the type of object is different; among them, the priority from high to low is: create operation, alter operation, insert operation, update operation, select operation.
[0063] In this example, the create operation is also called the creation operation, which is used to create type objects (such as tables, views, indexes, etc.). Before any operation is performed, the corresponding type object must exist first. Therefore, the create operation has the highest priority and is executed first. The alter operation is also called the modification operation, which is used to modify existing type objects (such as adding fields, modifying field types, etc.). Before inserting or updating data, you may need to make structural adjustments to the type object to ensure that the data can be stored and processed correctly. The insert operation is also called the insert operation, which is used to insert new data into the type object. Before querying or updating data, data must exist in the database. Therefore, the insert operation is executed before the update and select operations. Optionally, the priorities of the alter operation and the insert operation can be interchangeable. The update operation is also called the update operation, which is used to modify existing data in the type object. Before querying data, you may need to update the existing data to ensure the accuracy and timeliness of the query results. Therefore, the update operation has a higher priority than the select operation. The select operation is also called the query operation, which is used to query data from the database object. The select operation is usually used to obtain the latest data status, so it should be executed after all data modification operations to ensure the accuracy of the query results. The solution in this example, by limiting the priority of operation methods under the same type of object, can ensure that the creation and modification of database objects precede data operations, and the insertion and update of data precede data queries, thereby ensuring the logic and consistency of operations of type objects.
[0064] As another example, in step 102, temporary statements corresponding to different attributes of the type object under each operation method are generated according to the object information, including:
[0065] According to the grammatical rules corresponding to different attributes of the type object under each operation method, temporary statements corresponding to different attributes of the type object under each operation method are generated.
[0066] In this example, the grammar rules can be Backus-Naur Form (BNF), Extended Backus-Naur Form (EBNF), Parsing Expression Grammar (PEG), etc. After obtaining the grammar rules corresponding to different attributes of the type object under each operation method, the grammar rules are subjected to lexical analysis and grammatical analysis to obtain a grammar tree, and the grammar tree is traversed to generate a temporary statement. Exemplarily, a lexical analyzer can be used to convert the input character stream into a token. These tokens are the basic units of grammatical analysis, representing the basic components in the grammar, such as keywords, identifiers, operators, etc. Exemplarily, a grammar analyzer can be used to convert the token sequence into a grammar tree according to the grammar rules. The grammar tree is a hierarchical representation of the input structure, showing the grammatical structure of the input. In the traversal of the grammar tree, according to the node type and structure of the grammar tree, the corresponding temporary statement fragments are generated, and finally combined into a complete temporary statement. Exemplarily, the temporary statement is an SQL statement. The solution of this example generates temporary statements corresponding to different attributes of the type object under each operation method according to the grammatical rules corresponding to different attributes of the type object under each operation method, provides an automatic generation process of temporary statements, and improves the efficiency of temporary statement generation.
[0067] As another example, Figure 6A flow chart of a test library case generation method is exemplarily shown in the figure. Based on any example, after the actual object in the database to be tested is abstracted to obtain the object information of the type object, the generation priority of the temporary statement of the type object is determined according to the relationship information under the object information of the type object. Specifically, if the type object has a combination relationship with other type objects, the generation priority of the temporary statement of the type object and the other type objects is set to high; wherein, the priority of the included type object is higher than the priority of the included type object; if the type object has a dependency relationship with other type objects, the generation priority of the temporary statement of the type object and the other type objects is set to medium; wherein, the priority of the dependent type object is higher than the priority of the dependent type object; if the type object has an association relationship with other type objects, the generation priority of the temporary statement of the type object and the other type objects is set to low. It should be noted that there may be multiple relationships with multiple type objects under the relationship information of the object information of each type object, so each type object will perform three relationship information judgments. Under each type object, according to the generation priority of the temporary statement corresponding to the different operation methods of the type object, according to the grammatical rules corresponding to the different attributes of the type object under each operation method, the temporary statements corresponding to the different attributes of the type object under each operation method are generated. Replace the temporary object identifier in the temporary statement with a unified object identifier of the same type as the type object, and obtain a unified statement corresponding to different attributes of the type object under each operation method; replace the unified object identifier in the unified statement with the object identifier of each object to be tested under the type corresponding to the unified object identifier. And write the statement obtained after replacing the object identifier of the object to be tested each time into the SQL file to obtain a test case set; wherein the test case set includes the statement corresponding to each object to be tested under each operation method.
[0068] The test case generation method provided in this embodiment includes: abstracting the actual objects in the database to be tested to obtain the object information of the type object; generating temporary statements corresponding to different attributes of the type object under each operation method according to the object to be tested in the test requirements of the database to be tested; replacing the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object according to the object to be tested in the test requirements of the database to be tested, and writing the statement obtained after each replacement into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute, and the test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios.
[0069] Embodiment 2
[0070] Figure 7The structure diagram of the test case generation device provided by the embodiment of the present application is exemplarily shown in FIG. Figure 7 As shown, the device comprises:
[0071] Abstraction module 71, used for abstracting the actual objects in the database to be tested to obtain object information of type objects; wherein different type objects represent different types; object information includes attributes, operation methods and relationship information;
[0072] A generating module 72, for generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information;
[0073] The replacement module 73 is used to replace the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type object according to the object to be tested in the test requirements of the database to be tested, and flush the statement obtained after each replacement into the SQL file to obtain a test case set; wherein the test case set includes the statements corresponding to each object to be tested under each operation method.
[0074] In practical applications, there are many ways to implement the test case generation device. For example, it can be implemented through a computer program, such as application software, etc.; or, it can be implemented as a medium storing relevant computer programs, such as a USB flash drive, a cloud disk, etc.; or, it can be implemented through a physical device that integrates or installs relevant computer programs, such as a chip, etc.
[0075] Exemplarily, the actual objects in the database to be tested can be abstracted by modeling to obtain the object information of the type object. In practical applications, the modeling process can be implemented by modeling languages such as Unified Modeling Language (UML) or Systems Modeling Language (SysML). Among them, the actual objects in the database to be tested refer to the objects in the data structure of the database to be tested that have been stored. The actual objects may include all the objects in the database to be tested, or the selected objects to be tested. For example, the actual objects may include any of the following: tables, fields, functions, stored procedures, packages, views, synonyms, and triggers. Accordingly, the actual objects are abstracted to obtain the type objects; for example, there are two actual objects, Table A and Table B, in the database, and the corresponding type objects are all table type objects. The object information of the type object may include attributes such as common attributes, partition attributes, integration attributes, local attributes, and global attributes, operation methods such as create operations, modify operations, update operations, and delete operations, and relationship information such as the combination relationship, association relationship, dependency relationship, and inheritance relationship between objects. The object information of the type object includes the attributes, operation methods and associations of the actual object; for example, the attributes under the object information of the table type object include two attribute information: the global attributes of the actual object table A and the local attributes of the actual object table B. For example, taking the example of obtaining a modeling model including the type object by modeling, the following can be obtained: Figure 2 The type object model diagram shown is an example. Figure 2 The type object model shown includes: attribute sub-model, operation method sub-model, relationship information sub-model. In actual application, in the type object model, a mapping relationship between the type object and the object information under each sub-model can be established according to the same type object.
[0076] After obtaining the object information of the type object, a temporary statement corresponding to different attributes of the type object under each operation method is generated according to the object information. Exemplarily, obtaining the type object and the object information of the type object, generating a temporary statement can be executed in advance and the temporary statement can be stored, and the stored temporary statement can be called after receiving the test requirements. In this example, the temporary statement is generated based on two dimensions, namely the operation method of the type object and the attribute of the type object. In actual applications, the attributes and operation methods in the object information of each type object are traversed and combined, and a temporary statement is generated based on the combined attributes and operation methods. For example, for a table type object, a temporary statement corresponding to the creation of a global table can be generated; optionally, the temporary statement can also represent statements that call each other between multiple type objects, such as for a function type object, a temporary statement is created that can call a global function of a global table.
[0077] After obtaining the temporary statement corresponding to the type object, according to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is written into the structured query language (SQL) file to obtain a test case set; wherein the test case set includes the corresponding statements of each object to be tested under each operation method. In this example, the object to be tested is also an actual object existing in the database to be tested. In practical applications, the test requirements can be the case where function A operates view B, and view B operates table C at the same time. According to the type objects of the three objects, the temporary statements of the corresponding operations and corresponding attributes are matched, and the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object. It should be noted that the object name created by the temporary statement when it is generated may be random, and the names of the same object may be different in the temporary statements of different types of objects operating the same type of object. Therefore, the logic and code executableness of the generated statements can be enhanced by replacing the identifier. Exemplarily, the test requirement of the same test may include statements after identifier replacement corresponding to multiple operation methods, and the multiple statements are flushed into the SQL file as a test case set corresponding to the test requirement.
[0078] In the test case generation device provided by the present application, the actual objects in the database to be tested are abstracted to obtain the object information of the type object; based on the object information, temporary statements corresponding to different attributes of the type object under each operation method are generated; based on the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is written into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute, and the test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios.
[0079] In one example, the replacement module 73 is specifically configured to:
[0080] According to the type of the object to be tested, determine the unified object identifier under each type;
[0081] The temporary object identifier in the temporary statement is replaced with a unified object identifier of the same type as the type object, so as to obtain a unified statement corresponding to different attributes of the type object under each operation method;
[0082] The unified object identifier in the unified statement is replaced by the object identifier of each object to be tested under the type corresponding to the unified object identifier.
[0083] In this example, in the statement dimension, the temporary object identifier in the temporary statement corresponding to the type object is replaced with a unified object identifier of the same type as the type of the type object, and a unified statement corresponding to different attributes of the type object under each operation method is obtained, and then the unified object identifier in the unified statement is replaced with the object identifier of each object to be tested under the type corresponding to the unified object identifier. For example, the identifier of the same type of object in the temporary statements of different type objects is random and inconsistent because it is temporarily generated. The solution of this example can improve the readability and consistency of different temporary statements by replacing them with a unified object identifier, and improve the continuity of the test in the subsequent test case execution stage. At the same time, replacing the object identifier of the object to be tested with the object identifier of the object to be tested can realize the test of the object to be tested.
[0084] In one example, the generation module 72 is further used to: determine the generation priority of the temporary statement of the type object;
[0085] The generation module 72 is specifically used to generate temporary statements corresponding to different attributes of the type object under each operation method according to the generation priority and object information.
[0086] In actual applications, the priority of temporary statement generation of type objects can be fixed, or determined according to the number of actual objects under the type object. For example, the more actual objects there are in the database to be tested, the higher the priority of temporary statement generation of the corresponding type object. Optionally, the priority of the type object can also be determined according to the logical sequence of the operation methods of the type object under the object information. Optionally, the priority of temporary statement generation of the type object can also be determined according to the attributes of the type object under the object information, such as according to the scope of the type object, such as the priority of the type object of global attributes is higher than the priority of the type object of local attributes. The scheme of this example generates temporary statements corresponding to different attributes of the type object under each operation method according to the generation priority and object information, which can improve the flexibility of temporary statement generation of the type object.
[0087] In one example, the generating module 72 is specifically configured to:
[0088] Determine the generation priority of temporary statements of the type object according to the relationship information under the object information of the type object;
[0089] If a type object has a combination relationship with other type objects, the priority of temporary statement generation between the type object and other type objects is set to high; wherein, the priority of the included type object is higher than the priority of the included type object;
[0090] If a type object has a dependency relationship with other type objects, the priority of temporary statement generation between the type object and other type objects is set to medium; the priority of the dependent type object is higher than the priority of the dependent type object;
[0091] If a type object is associated with other type objects, the temporary statement generation priority of the type object and other type objects is set to low.
[0092] The scheme of this example determines the priority of generating temporary statements of type objects according to the logical relationship between different types of objects. Among them, the combination relationship refers to that one type object contains another type object. For example, table and field: a table is composed of multiple fields. Among them, the priority of the included type object, i.e., field, is higher than the priority of the included type object, i.e., table. The dependency relationship refers to that the existence of one type object depends on another type object. For example, view and table: a view is created based on a table, so the view depends on the table; stored procedure and table: the SQL statement in the stored procedure may reference the table, so the stored procedure depends on these tables; trigger and table: a trigger is triggered based on an event of the table, so the trigger depends on the table. Among them, the priority of the dependent type object, i.e., table, is higher than the priority of the included type object, i.e., view. The association relationship refers to that objects are related to each other in some way. For example, tables are related through foreign keys, and foreign keys in one table reference the primary key of another table; index and table: indexes are created based on the columns of a table. Although indexes do not depend on the existence of tables, there is an association between them; synonyms and original objects: synonyms are references to original objects for easy access. Since there is no strict logical order between the two type objects in the association relationship, the internal priority of the two may not be specified. The solution of this example can improve the logic of temporary statement generation by determining the generation priority of temporary statements of type objects according to the relationship information under the object information of the type objects.
[0093] In one example, the generating module 72 is specifically configured to:
[0094] For the same type of object, the generation priority of temporary statements corresponding to different operation methods of the type of object is different; among them, the priority from high to low is: create operation, alter operation, insert operation, update operation, select operation.
[0095] In this example, the create operation is also called the creation operation, which is used to create type objects (such as tables, views, indexes, etc.). Before any operation is performed, the corresponding type object must exist first. Therefore, the create operation has the highest priority and is executed first. The alter operation is also called the modification operation, which is used to modify existing type objects (such as adding fields, modifying field types, etc.). Before inserting or updating data, you may need to make structural adjustments to the type object to ensure that the data can be stored and processed correctly. The insert operation is also called the insert operation, which is used to insert new data into the type object. Before querying or updating data, data must exist in the database. Therefore, the insert operation is executed before the update and select operations. Optionally, the priorities of the alter operation and the insert operation can be interchangeable. The update operation is also called the update operation, which is used to modify existing data in the type object. Before querying data, you may need to update the existing data to ensure the accuracy and timeliness of the query results. Therefore, the update operation has a higher priority than the select operation. The select operation is also called the query operation, which is used to query data from the database object. The select operation is usually used to obtain the latest data status, so it should be executed after all data modification operations to ensure the accuracy of the query results. The solution in this example, by limiting the priority of operation methods under the same type of object, can ensure that the creation and modification of database objects precede data operations, and the insertion and update of data precede data queries, thereby ensuring the logic and consistency of operations of type objects.
[0096] In one example, the generating module 72 is specifically configured to:
[0097] According to the grammatical rules corresponding to different attributes of the type object under each operation method, temporary statements corresponding to different attributes of the type object under each operation method are generated.
[0098] In this example, the grammar rules can be Backus-Naur Form (BNF), Extended Backus-Naur Form (EBNF), Parsing Expression Grammar (PEG), etc. After obtaining the grammar rules corresponding to different attributes of the type object under each operation method, the grammar rules are subjected to lexical analysis and grammatical analysis to obtain a grammar tree, and the grammar tree is traversed to generate a temporary statement. Exemplarily, a lexical analyzer can be used to convert the input character stream into a token. These tokens are the basic units of grammatical analysis, representing the basic components in the grammar, such as keywords, identifiers, operators, etc. Exemplarily, a grammar analyzer can be used to convert the token sequence into a grammar tree according to the grammar rules. The grammar tree is a hierarchical representation of the input structure, showing the grammatical structure of the input. In the traversal of the grammar tree, according to the node type and structure of the grammar tree, the corresponding temporary statement fragments are generated, and finally combined into a complete temporary statement. Exemplarily, the temporary statement is an SQL statement. The solution of this example generates temporary statements corresponding to different attributes of the type object under each operation method according to the grammatical rules corresponding to different attributes of the type object under each operation method, provides an automatic generation process of temporary statements, and improves the efficiency of temporary statement generation.
[0099] In the test case generation device provided by this embodiment: the actual objects in the database to be tested are abstracted to obtain the object information of the type object; based on the object information, temporary statements corresponding to different attributes of the type object under each operation method are generated; based on the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type object, and the statement obtained after each replacement is written into the SQL file to obtain a test case set. In the scheme of this example, the generation of temporary statements takes into account the object type, operation method and object attribute, and the test case can be generated by replacing the identifier of the object to be tested in the historical statement, thereby improving the applicability of the database test case in complex test scenarios.
[0100] Embodiment 3
[0101] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, the electronic device comprising:
[0102] The electronic device includes a processor 291 and a memory 292; it may also include a communication interface 293 and a bus 294. The processor 291, the memory 292, and the communication interface 293 may communicate with each other through the bus 294. The communication interface 293 may be used for information transmission. The processor 291 may call the logic instructions in the memory 292 to execute the above-mentioned example method.
[0103] In addition, the logic instructions in the above-mentioned memory 292 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0104] The memory 292 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the methods in the embodiments of the present application. The processor 291 executes functional applications and data processing by running the software programs, instructions, and modules stored in the memory 292, that is, implementing the methods in the above method examples.
[0105] The memory 292 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 292 may include a high-speed random access memory and may also include a non-volatile memory.
[0106] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the method in any embodiment.
[0107] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in any embodiment when the computer program is executed by a processor.
[0108] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0109] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A test case generation method, characterized in that: include: Abstract the actual objects in the database to be tested to obtain object information of type objects; wherein different type objects represent different types; the object information includes attributes, operation methods and relationship information; Generate temporary statements corresponding to different attributes of the type of object under each operation method according to the object information; According to the object to be tested in the test requirements of the database to be tested, the temporary object identifier in the temporary statement is replaced with the object identifier of the object to be tested of the same type as the type of object, and the statement obtained after each replacement is flushed into the SQL file to obtain a test case set; wherein the test case set includes statements corresponding to each object to be tested under each operation method.
2. The method according to claim 1, characterized in that The step of replacing the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type of the object according to the object to be tested in the test requirements of the database to be tested comprises: According to the type of the object to be tested, determine a unified object identifier under each type; The temporary object identifier in the temporary statement is replaced with the unified object identifier of the same type as the type of the type object, to obtain a unified statement corresponding to different attributes of the type object under each operation method; The unified object identifier in the unified statement is replaced by the object identifier of each object to be tested under the type corresponding to the unified object identifier.
3. The method according to claim 1, characterized in that Before generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information, the method further includes: Determining a generation priority of the temporary statements of the type of object; The step of generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information includes: According to the generation priority and the object information, temporary statements corresponding to different attributes of the type object under each operation method are generated.
4. The method according to claim 3, characterized in that The determining of the generation priority of the temporary statement of the type object includes: Determining a generation priority of the temporary statement of the type object according to the relationship information under the object information of the type object; If the type object has a combination relationship with other type objects, the priority of generating the temporary statement between the type object and other type objects is set to high; wherein the priority of the included type object is higher than the priority of the included type object; If the type object has a dependency relationship with other type objects, the priority of generating temporary statements between the type object and other type objects is set to medium; wherein the priority of the dependent type object is higher than the priority of the dependent type object; If the type object has an association relationship with other type objects, the temporary statement generation priority of the type object and other type objects is set to low.
5. The method according to claim 3, characterized in that: The determining of the generation priority of the temporary statement of the type object includes: For the same type of object, different operation methods of the type of object correspond to different generation priorities of the temporary statements; wherein the priorities are from high to low: create operation, alter operation, insert operation, update operation, select operation.
6. The method according to any one of claims 1 to 5, characterized in that: The step of generating temporary statements corresponding to different attributes of the type object under each operation method according to the object information includes: According to the grammatical rules corresponding to the different attributes of the type object under each operation method, a temporary statement corresponding to the different attributes of the type object under each operation method is generated.
7. A test case generating device, characterized in that: include: An abstraction module is used to abstract the actual objects in the database to be tested to obtain object information of type objects; wherein different type objects represent different types; the object information includes attributes, operation methods and relationship information; A generation module, used for generating temporary statements corresponding to different attributes of the type of object under each operation method according to the object information; A replacement module is used to replace the temporary object identifier in the temporary statement with the object identifier of the object to be tested of the same type as the type of object according to the object to be tested in the test requirements of the database to be tested, and to flush the statement obtained after each replacement into the SQL file to obtain a test case set; wherein the test case set includes the statements corresponding to each object to be tested under each operation method.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The method comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.