A software test driven code generation method and device
By constructing and supplementing the knowledge graph of database test cases and generating integrated test cases for target business scenarios, the problem of low test case coverage and efficiency in database development is solved, and the efficiency of database development is improved.
Patent Information
- Application Number
- CN202410902770.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2044-07-08
AI Technical Summary
In the existing technology, the coverage and effectiveness of test cases in the database development process are low, resulting in low database development efficiency.
By obtaining the dependencies between conventional test cases of the basic functional types of the database, a knowledge graph is constructed, and supplemented based on the execution results, and finally an integration test case for the target business scenario is generated to improve the coverage and efficiency of the test cases.
It improves the coverage and efficiency of test cases in the database development process, thereby improving the efficiency of database development.
Smart Images

Figure CN118445212B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network technology, and in particular to a software test-driven code generation method and device. Background Art
[0002] Test-Driven Development (TDD) is a software development methodology that emphasizes writing test cases before writing new code. The basic idea of TDD is to write failing test cases first, then write enough code to make the tests pass, and finally refactor to eliminate duplicate code or improve code quality. The basic process of TDD usually includes the following steps: Write test cases: First determine the functions or features to be developed, and then write one or more test cases for these functions. These test cases will fail before you start writing actual code. Write enough code: Next, write enough code to make the tests just written pass. This may mean writing only the minimum code to satisfy the test cases without implementing the entire function. Run the tests: Run the written test cases to make sure they all pass. If any test fails, you need to continue to modify the code until the test passes. Refactor the code: Once the test passes, you can refactor the code to eliminate duplicate code, improve readability, or optimize performance. In this step, make sure that the test still passes. The advantages of TDD include improving code quality, reducing debugging time, and enhancing code maintainability and extensibility. However, TDD also requires more time and effort because additional test cases need to be written and run in each iteration.
[0003] TDD can also be used for database development and code writing. During development, developers often only generate test cases for basic database operation functions, that is, database basic function test cases, and then perform subsequent optimization and integration based on the execution results and actual needs of the database basic function test cases during the development process. They do not generate corresponding business scenario test cases based on the actual business scenarios of the database, which will result in low coverage and efficiency of test cases, and thus low database development efficiency. Summary of the invention
[0004] The present invention provides a software test-driven code generation method and device, which are used to solve the problems of low coverage and low efficiency of test cases in the prior art.
[0005] In one aspect, the present invention provides a software test-driven code generation method, comprising:
[0006] For the database to be written, multiple conventional test case sets corresponding to the database to be written are obtained, and each conventional test case set corresponds to a basic function type of the database;
[0007] Obtain the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and take each conventional test case as an entity, and take the first dependency relationship between each conventional test case as an entity relationship to construct a first test case knowledge graph; wherein the first dependency relationship indicates the calling relationship between each conventional test case;
[0008] Based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, the first test case knowledge graphs are merged to obtain the second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case;
[0009] Execute each conventional test case to obtain a corresponding execution result, and supplement the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph;
[0010] Obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
[0011] In an optional embodiment of the present application, obtaining a first dependency relationship between conventional test cases in a conventional test case set of each database basic function type includes:
[0012] The input, output and functions of any two regular test cases are analyzed. If at least one of the functional flow dependency, input-output association, functional coverage, precondition and postcondition relationship and functional logic and business process relationship exists between any two regular test cases, it is determined that there is a first dependency relationship between any two regular test cases.
[0013] In an optional embodiment of the present application, the method may further include:
[0014] For any two regular test cases, if there is at least one of the relationship between database table structure and constraints, the foreign key association relationship between database tables, the relationship between index and query performance, and database transaction management between any two regular test cases, it is determined that there is a second dependency relationship between any two regular test cases.
[0015] In an optional embodiment of the present application, based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, each first test case knowledge graph is merged to obtain a second test case knowledge graph, including:
[0016] The conventional test cases corresponding to each second dependency are the head entity and the tail entity respectively, and the second dependency is the entity relationship, and the corresponding test case triples are constructed;
[0017] Perform business logic verification on each triple, delete the test case triples that fail the logic verification, retain the test case triples that pass the logic verification, and merge the retained test case triples with each first test case knowledge graph to obtain a second test case knowledge graph.
[0018] In an optional embodiment of the present application, each conventional test case is executed separately to obtain a corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph, including:
[0019] For any conventional test case, obtaining a first dependency relationship between an execution result of the conventional test case and another conventional test case in the triplet where the conventional test case is located; wherein the execution result includes success or failure;
[0020] The execution result is used as the head entity, another regular test case is used as the tail entity, and the corresponding first dependency relationship is used as the entity relationship to construct the corresponding triple;
[0021] Add the triples corresponding to each execution result to the second test case knowledge graph to obtain the third test case knowledge graph.
[0022] In an optional embodiment of the present application, obtaining a specification text of at least one target business scenario, searching the third test case knowledge graph based on the specification text of each target business scenario, and obtaining a test case relationship chain corresponding to the target business scenario includes:
[0023] For any target business scenario, semantic analysis and keyword extraction are performed on the specification text of the target business scenario to obtain result words, which include test case indicator words and dependency indicator words;
[0024] Locate at least one starting test case in the third test case knowledge graph based on the test case indicator, and then determine subsequent test cases of each starting test case based on the dependency indicator to obtain a corresponding initial test case relationship chain;
[0025] Based on each initial test case relationship chain, a test case relationship chain is determined.
[0026] In an optional embodiment of the present application, determining a test case relationship chain based on each initial test case relationship chain includes:
[0027] The input of each initial test case relationship chain is compared with the input of the target business scenario, the output of each initial test case relationship chain is compared with the output of the target business scenario, and the initial test cases whose input and output in each initial test case relationship chain match the input and output of the target business scenario are determined as the test case relationship chain of the target business scenario.
[0028] In a second aspect, the present invention further provides a software test driven code generation device, comprising:
[0029] A conventional test case set acquisition module is used to acquire multiple conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type;
[0030] A first test case knowledge graph acquisition module is used to acquire the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and take each conventional test case as an entity and the first dependency relationship between each conventional test case as an entity relationship to construct a first test case knowledge graph; wherein the first dependency relationship indicates a call relationship between each conventional test case;
[0031] A second test case knowledge graph acquisition module is used to fuse the first test case knowledge graphs based on the second dependency relationship between the conventional test cases in the conventional test set of multiple database basic function types to obtain the second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between the conventional test cases;
[0032] A third test case knowledge graph acquisition module is used to execute each conventional test case to obtain a corresponding execution result, and to supplement the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph;
[0033] An integrated test case acquisition module is used to obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
[0034] In an optional embodiment of the present application, the first test case knowledge graph acquisition module is specifically used to:
[0035] The input, output and functions of any two regular test cases are analyzed. If at least one of the functional flow dependency, input-output association, functional coverage, precondition and postcondition relationship and functional logic and business process relationship exists between any two regular test cases, it is determined that there is a first dependency relationship between any two regular test cases.
[0036] In an optional embodiment of the present application, the second test case knowledge graph acquisition module is further used to:
[0037] For any two regular test cases, if there is at least one of the relationship between database table structure and constraints, the foreign key association relationship between database tables, the relationship between index and query performance, and database transaction management between any two regular test cases, it is determined that there is a second dependency relationship between any two regular test cases.
[0038] In an optional embodiment of the present application, the second test case knowledge graph acquisition module is specifically used to:
[0039] The conventional test cases corresponding to each second dependency are the head entity and the tail entity respectively, and the second dependency is the entity relationship, and the corresponding test case triples are constructed;
[0040] Perform business logic verification on each triple, delete the test case triples that fail the logic verification, retain the test case triples that pass the logic verification, and merge the retained test case triples with each first test case knowledge graph to obtain a second test case knowledge graph.
[0041] In an optional embodiment of the present application, the third test case knowledge graph acquisition module is specifically used to:
[0042] For any conventional test case, obtaining a first dependency relationship between an execution result of the conventional test case and another conventional test case in the triplet where the conventional test case is located; wherein the execution result includes success or failure;
[0043] The execution result is used as the head entity, another regular test case is used as the tail entity, and the corresponding first dependency relationship is used as the entity relationship to construct the corresponding triple;
[0044] Add the triples corresponding to each execution result to the second test case knowledge graph to obtain the third test case knowledge graph.
[0045] In an optional embodiment of the present application, the integrated test case acquisition module is specifically used to:
[0046] For any target business scenario, semantic analysis and keyword extraction are performed on the specification text of the target business scenario to obtain result words, which include test case indicator words and dependency indicator words;
[0047] Locate at least one starting test case in the third test case knowledge graph based on the test case indicator, and then determine subsequent test cases of each starting test case based on the dependency indicator to obtain a corresponding initial test case relationship chain;
[0048] Based on each initial test case relationship chain, a test case relationship chain is determined.
[0049] In an optional embodiment of the present application, the integrated test case acquisition module is further used to:
[0050] The input of each initial test case relationship chain is compared with the input of the target business scenario, the output of each initial test case relationship chain is compared with the output of the target business scenario, and the initial test cases whose input and output in each initial test case relationship chain match the input and output of the target business scenario are determined as the test case relationship chain of the target business scenario.
[0051] In a third aspect, the present invention further provides an electronic 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 program, the code generation method driven by software testing as described above is implemented.
[0052] In a fourth aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the software test-driven code generation methods described above.
[0053] In a fifth aspect, the present invention further provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the software test-driven code generation methods described above.
[0054] The present invention provides a software test-driven code generation method and device, which constructs a first test case knowledge graph by acquiring the first dependency between each conventional test case in the conventional test case set of each database basic function type; based on the second dependency between each conventional test case in the conventional test case set of multiple database basic function types, each first test case knowledge graph is merged to obtain a second test case knowledge graph; each conventional test case is executed to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph; the specification text of at least one target business scenario is acquired, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integrated test case corresponding to the target business scenario is generated based on the test case relationship chain. In the process of database development, the scheme not only generates conventional test cases corresponding to the basic functions of the database, but also generates integrated test cases corresponding to different business scenarios through the knowledge graph generated by the first dependency and the second dependency between the conventional test cases, so that the coverage and efficiency of the test cases in the database development process are higher, thereby improving the efficiency of database development. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0056] Figure 1 A schematic diagram of a flow chart of a software test driven code generation method provided by the present invention;
[0057] Figure 2 A structural block diagram of a software test driven code generation device provided by the present invention;
[0058] Figure 3 This is a schematic structural diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0059] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0060] Figure 1 A flowchart of a software test driven code generation method provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method may include:
[0061] Step S101 : for a database to be written, a plurality of conventional test case sets corresponding to the database to be written are obtained, and each conventional test case set corresponds to a database basic function type.
[0062] Among them, test cases for database basic functions can include the following categories:
[0063] Functional test cases: used to ensure that the database can correctly store, update, and delete data; ensure that the database can correctly execute various query operations, such as simple queries, complex queries, aggregate function queries, etc.
[0064] Performance test cases: Test the performance of the database under various load conditions, including concurrent queries, large data volume operations, etc.
[0065] Security test cases: Test the security of the database, including protection against unauthorized access, data encryption, prevention of SQL injection, etc.
[0066] Fault tolerance test cases: Test the performance of the database under abnormal conditions, such as power outages, system crashes, data loss, etc.
[0067] Compatibility test cases: Test the compatibility of the database with other software, operating systems, and hardware.
[0068] Each of the above basic database function types needs to generate multiple test cases (i.e., regular test cases), and then a regular test case type set corresponding to each basic database function type can be obtained.
[0069] Specifically, conventional test cases may be obtained by manually writing them, or by various automatically generating methods.
[0070] Step S102, obtain the first dependency relationship between each regular test case in the regular test case set of each database basic function type, and take each regular test case as an entity, and the first dependency relationship between each regular test case as an entity relationship to construct a first test case knowledge graph; wherein the first dependency relationship indicates the calling relationship between each regular test case.
[0071] Among them, the first dependency relationship may include: functional process dependency relationship, input-output association relationship, functional coverage relationship, precondition and postcondition relationship, and functional logic and business process relationship.
[0072] Specifically, this step is to obtain the dependency relationship between each conventional test case in the same type of database basic function type, and then construct the first test case knowledge graph. This knowledge graph can comprehensively reflect the dependency relationship information between each conventional test case in the same type of database basic function type, and provide a basis for the subsequent acquisition of a comprehensive and effective test case relationship chain corresponding to the business scenario.
[0073] Step S103, based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, the first test case knowledge graphs are merged to obtain the second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case.
[0074] The second dependency relationship may include: a relationship between a database table structure and a constraint condition, a foreign key association relationship between database tables, a relationship between an index and query performance, and a database transaction management relationship.
[0075] Specifically, after obtaining the first test case knowledge graph corresponding to the same type of database basic function type in the previous step, the dependency relationship between conventional test cases of different types of database basic function types can be further utilized to fuse the first test case knowledge graph. Specifically, edges between conventional test cases of different types of database basic function types are constructed to obtain a larger second test case knowledge graph. The construction of the second test case knowledge graph comprehensively integrates different types of database basic function types, making the information in the knowledge graph more comprehensive, and further providing a basis for the subsequent acquisition of comprehensive and effective test case relationship chains corresponding to business scenarios.
[0076] Step S104, execute each conventional test case respectively to obtain a corresponding execution result, supplement the second test case knowledge graph based on each execution result, and obtain a third test case knowledge graph.
[0077] The execution results of the test cases include failure and success.
[0078] Specifically, since the execution results of conventional test cases can include failure and success, and different execution results may cause the next test case with an associated relationship to have different execution or optimization results, the second test case knowledge graph can be further completed by adding execution result information in this step, so that the information contained in the obtained third knowledge graph is more comprehensive, thereby further providing a basis for the subsequent acquisition of a comprehensive and effective test case relationship chain corresponding to the business scenario.
[0079] Step S105, obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
[0080] After obtaining the third test case knowledge graph in the above steps, the corresponding integrated test case can be constructed for the target business scenario. For example, in the e-commerce field, the target business scenario can be: to evaluate the purchased goods, verify that the evaluation information is correctly stored in the corresponding feedback data table and associated with the correct product and user; to create an order, verify that the order information is correctly stored in the order data table, and the order is associated with the correct user and product.
[0081] Specifically, first obtain the specification text of the target business scenario, which can be a description text of the target business scenario process. Then perform semantic parsing and keyword extraction on the specification text, and finally use the extracted keywords to search in the third test case knowledge graph to obtain the test case relationship chain corresponding to the target business scenario, and merge these test cases to obtain the final integrated test case.
[0082] It is understandable that in the development process of the database to be written, the above conventional test cases and integrated test cases will be executed, and will be optimized and improved based on the results of the execution, and finally the writing of the database will be completed. However, in this application, the corresponding knowledge graph is generated through the dependencies and execution results between the above conventional test cases, and the integrated test cases suitable for the business scenario are finally obtained from the knowledge graph, and the coverage and efficiency of the integrated test cases are well guaranteed.
[0083] The solution provided by the present application is to construct a first test case knowledge graph by obtaining the first dependency between each conventional test case in the conventional test case set of each database basic function type; based on the second dependency between each conventional test case in the conventional test case set of multiple database basic function types, each first test case knowledge graph is merged to obtain a second test case knowledge graph; each conventional test case is executed separately to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph; the specification text of at least one target business scenario is obtained, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integrated test case corresponding to the target business scenario is generated based on the test case relationship chain. In the process of database development, this solution not only generates conventional test cases corresponding to the basic functions of the database, but also generates integrated test cases corresponding to different business scenarios through the knowledge graph generated by the first dependency and the second dependency between conventional test cases, so that the coverage and efficiency of test cases in the database development process are higher, thereby improving the efficiency of database development.
[0084] In an optional embodiment of the present application, obtaining a first dependency relationship between conventional test cases in a conventional test case set of each database basic function type includes:
[0085] The input, output and functions of any two regular test cases are analyzed. If at least one of the functional flow dependency, input-output association, functional coverage, precondition and postcondition relationship and functional logic and business process relationship exists between any two regular test cases, it is determined that there is a first dependency relationship between any two regular test cases.
[0086] Functional flow dependencies refer to the fact that test cases may cover different operation paths of the same function. For example, a functional test case for an e-commerce website may include operations such as user registration, product browsing, adding to shopping cart, and checkout. There are dependencies between these test cases because users must perform these operations in a specific order.
[0087] Input-output association means that the input and output of the test cases may be dependent on each other. For example, a functional test case for form validation needs to first verify the correctness of the form input and then verify whether the form submission operation is successful.
[0088] Functional coverage means that different test cases may cover different aspects or parameter combinations of the same function. For example, a test case for a search function may cover different aspects such as keyword search, advanced search, filtering and sorting. These test cases together ensure the comprehensive testing of the search function.
[0089] Precondition and postcondition relationships: The relationships between test cases may be based on the settings of preconditions and postconditions. For example, a test case for a shopping cart feature needs to ensure that the shopping cart is empty before adding items to the shopping cart, and confirm that the items in the shopping cart have been removed after checkout.
[0090] Functional logic and business process relationship means that test cases may be related to each other according to the complexity of functional logic and business process. For example, a test case of a bank transfer function needs to test the validity of the transfer amount, the validity of the recipient's account, and whether the account balance is correct after the transfer is successful.
[0091] In an optional embodiment of the present application, the method further includes:
[0092] For any two regular test cases, if there is at least one of the relationship between database table structure and constraints, the foreign key association relationship between database tables, the relationship between index and query performance, and database transaction management between any two regular test cases, it is determined that there is a second dependency relationship between any two regular test cases.
[0093] Among them, database table structure and constraints refer to the database table structure, which refers to the columns of each table and their data types, lengths, default values, etc. Constraints include primary key constraints, unique constraints, foreign key constraints, check constraints, etc., which restrict the insertion and update behavior of data. Test cases need to consider these constraints to ensure that the system behaves correctly under different conditions.
[0094] Foreign key relationships between tables refer to the fact that tables in a database are usually associated through foreign key relationships, which play an important role in data operations and queries. Test cases need to verify whether these relationships are correctly maintained and used.
[0095] The relationship between index and query performance means that the index in the database is crucial to query performance. Test cases should not only verify the insertion and update of data, but also test the performance and correctness of query operations to ensure the effective use of indexes.
[0096] Database transaction management refers to transaction management involving data consistency and persistence. Test cases need to verify the opening, committing and rolling back of transactions, as well as their behavior under different concurrent access conditions.
[0097] In an optional embodiment of the present application, based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, each first test case knowledge graph is merged to obtain a second test case knowledge graph, including:
[0098] The conventional test cases corresponding to each second dependency are the head entity and the tail entity respectively, and the second dependency is the entity relationship, and the corresponding test case triples are constructed;
[0099] Perform business logic verification on each triple, delete the test case triples that fail the logic verification, retain the test case triples that pass the logic verification, and merge the retained test case triples with each first test case knowledge graph to obtain a second test case knowledge graph.
[0100] In an optional embodiment of the present application, the knowledge graph executes each conventional test case to obtain a corresponding execution result, and the second test case knowledge graph of the knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph, including:
[0101] For any conventional test case, obtain the first dependency relationship between the execution result of the knowledge graph conventional test case and another conventional test case in the triplet where the knowledge graph conventional test case is located; wherein the knowledge graph execution result includes success or failure;
[0102] Take the knowledge graph execution result as the head entity, another regular test case in the knowledge graph as the tail entity, and the corresponding first dependency as the entity relationship to construct the corresponding triple;
[0103] Add the triples corresponding to each execution result to the second test case knowledge graph of the knowledge graph to obtain the third test case knowledge graph of the knowledge graph.
[0104] It should be noted that when the execution result of a conventional test case is successful, it can be further subdivided into different states. Similarly, when the execution result of a conventional test case is failed, it can be further subdivided into different states. In these subdivided cases, the completion principle of the third test case knowledge graph is similar to that of the case without subdivision, and will not be repeated here.
[0105] In an optional embodiment of the present application, obtaining a specification text of at least one target business scenario, searching the third test case knowledge graph based on the specification text of each target business scenario, and obtaining a test case relationship chain corresponding to the target business scenario includes:
[0106] For any target business scenario, semantic analysis and keyword extraction are performed on the specification text of the target business scenario to obtain result words, which include test case indicator words and dependency indicator words;
[0107] Locate at least one starting test case in the third test case knowledge graph based on the test case indicator, and then determine subsequent test cases of each starting test case based on the dependency indicator to obtain a corresponding initial test case relationship chain;
[0108] Based on each initial test case relationship chain, a test case relationship chain is determined.
[0109] Among them, based on each initial test case relationship chain, a test case relationship chain is determined, including: comparing the input of each initial test case relationship chain with the input of the target business scenario, comparing the output of each initial test case relationship chain with the output of the target business scenario, and determining the initial test cases whose input and output in each initial test case relationship chain match the input and output of the target business scenario as the test case relationship chain of the target business scenario.
[0110] It should be noted that the integrated test cases corresponding to the target business scenarios are generated based on the test case relationship chain, and the test cases are fused using the entity relationships between the test cases in the relationship chain. The fusion process can be serial, parallel, reused, merged, etc., to finally obtain integrated test cases.
[0111] Figure 2 A structural block diagram of a software test driven code generation device is provided for an embodiment of the present invention, such as Figure 2 As shown, the device may include:
[0112] The conventional test case set acquisition module 201 is used to acquire multiple conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type;
[0113] The first test case knowledge graph acquisition module 202 is used to acquire the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and take each conventional test case as an entity and the first dependency relationship between each conventional test case as an entity relationship to construct a first test case knowledge graph; wherein the first dependency relationship indicates the calling relationship between each conventional test case;
[0114] The second test case knowledge graph acquisition module 203 is used to merge the first test case knowledge graphs based on the second dependency relationship between the conventional test cases in the conventional test set of multiple database basic function types to obtain the second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between the conventional test cases;
[0115] The third test case knowledge graph acquisition module 204 is used to execute each conventional test case to obtain a corresponding execution result, and supplement the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph;
[0116] The integrated test case acquisition module 205 is used to obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
[0117] The solution provided by the present application is to construct a first test case knowledge graph by obtaining the first dependency between each conventional test case in the conventional test case set of each database basic function type; based on the second dependency between each conventional test case in the conventional test case set of multiple database basic function types, each first test case knowledge graph is merged to obtain a second test case knowledge graph; each conventional test case is executed separately to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph; the specification text of at least one target business scenario is obtained, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integrated test case corresponding to the target business scenario is generated based on the test case relationship chain. In the process of database development, this solution not only generates conventional test cases corresponding to the basic functions of the database, but also generates integrated test cases corresponding to different business scenarios through the knowledge graph generated by the first dependency and the second dependency between conventional test cases, so that the coverage and efficiency of test cases in the database development process are higher, thereby improving the efficiency of database development.
[0118] In an optional embodiment of the present application, the first test case knowledge graph acquisition module is specifically used to:
[0119] The input, output and functions of any two regular test cases are analyzed. If at least one of the functional flow dependency, input-output association, functional coverage, precondition and postcondition relationship and functional logic and business process relationship exists between any two regular test cases, it is determined that there is a first dependency relationship between any two regular test cases.
[0120] In an optional embodiment of the present application, the second test case knowledge graph acquisition module is further used to:
[0121] For any two regular test cases, if there is at least one of the relationship between database table structure and constraints, the foreign key association relationship between database tables, the relationship between index and query performance, and database transaction management between any two regular test cases, it is determined that there is a second dependency relationship between any two regular test cases.
[0122] In an optional embodiment of the present application, the second test case knowledge graph acquisition module is specifically used to:
[0123] The conventional test cases corresponding to each second dependency are the head entity and the tail entity respectively, and the second dependency is the entity relationship, and the corresponding test case triples are constructed;
[0124] Perform business logic verification on each triple, delete the test case triples that fail the logic verification, retain the test case triples that pass the logic verification, and merge the retained test case triples with each first test case knowledge graph to obtain a second test case knowledge graph.
[0125] In an optional embodiment of the present application, the third test case knowledge graph acquisition module is specifically used to:
[0126] For any conventional test case, obtaining a first dependency relationship between an execution result of the conventional test case and another conventional test case in the triplet where the conventional test case is located; wherein the execution result includes success or failure;
[0127] The execution result is used as the head entity, another regular test case is used as the tail entity, and the corresponding first dependency relationship is used as the entity relationship to construct the corresponding triple;
[0128] Add the triples corresponding to each execution result to the second test case knowledge graph to obtain the third test case knowledge graph.
[0129] In an optional embodiment of the present application, the integrated test case acquisition module is specifically used to:
[0130] For any target business scenario, semantic analysis and keyword extraction are performed on the specification text of the target business scenario to obtain result words, which include test case indicator words and dependency indicator words;
[0131] Locate at least one starting test case in the third test case knowledge graph based on the test case indicator, and then determine subsequent test cases of each starting test case based on the dependency indicator to obtain a corresponding initial test case relationship chain;
[0132] Based on each initial test case relationship chain, a test case relationship chain is determined.
[0133] In an optional embodiment of the present application, the integrated test case acquisition module is further used to:
[0134] The input of each initial test case relationship chain is compared with the input of the target business scenario, the output of each initial test case relationship chain is compared with the output of the target business scenario, and the initial test cases whose input and output in each initial test case relationship chain match the input and output of the target business scenario are determined as the test case relationship chain of the target business scenario.
[0135] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330 and a communication bus 340, wherein the processor 310, the communication interface 320 and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the software test-driven code generation method, the method comprising: for a database to be written, obtaining a plurality of conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type; obtaining the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and taking each conventional test case as an entity, taking the first dependency relationship between each conventional test case as an entity relationship, and constructing a first test case knowledge graph; wherein the first dependency relationship indicates the calling relationship between each conventional test case; based on the conventional test sets of multiple database basic function types The second dependency relationship between each conventional test case is obtained, and the first test case knowledge graphs are merged to obtain a second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case; each conventional test case is executed separately to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph; the specification text of at least one target business scenario is obtained, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integration test case corresponding to the target business scenario is generated based on the test case relationship chain.
[0136] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0137] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the software test-driven code generation method provided by the above methods, and the method includes: for a database to be written, obtaining multiple conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type; obtaining the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and taking each conventional test case as an entity, and taking the first dependency relationship between each conventional test case as an entity relationship, to construct a first test case knowledge graph; wherein the first dependency relationship indicates each The calling relationship between conventional test cases; based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, the first test case knowledge graphs are merged to obtain the second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case; each conventional test case is executed separately to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain the third test case knowledge graph; the specification text of at least one target business scenario is obtained, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integration test case corresponding to the target business scenario is generated based on the test case relationship chain.
[0138] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a software test-driven code generation method provided by the above-mentioned methods, the method comprising: for a database to be written, obtaining a plurality of conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type; obtaining a first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and taking each conventional test case as an entity, and taking the first dependency relationship between each conventional test case as an entity relationship, to construct a first test case knowledge graph; wherein the first dependency relationship indicates a calling relationship between each conventional test case; based on Based on the second dependency relationship between each conventional test case in the conventional test set of multiple database basic function types, the first test case knowledge graphs are merged to obtain a second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case; each conventional test case is executed separately to obtain the corresponding execution result, and the second test case knowledge graph is supplemented based on each execution result to obtain a third test case knowledge graph; the specification text of at least one target business scenario is obtained, and the third test case knowledge graph is searched based on the specification text of each target business scenario to obtain the test case relationship chain corresponding to the target business scenario, and the integration test case corresponding to the target business scenario is generated based on the test case relationship chain.
[0139] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0140] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0141] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A software test-driven code generation method, characterized in that: include: For a database to be written, a plurality of conventional test case sets corresponding to the database to be written are obtained, and each conventional test case set corresponds to a database basic function type; Obtain the first dependency relationship between each conventional test case in the conventional test case set of each database basic function type, and take each conventional test case as an entity and the first dependency relationship between each conventional test case as an entity relationship to construct a first test case knowledge graph; wherein the first dependency relationship indicates a calling relationship between each conventional test case; Based on the second dependency relationship between each conventional test case in the conventional test set of the multiple database basic function types, the first test case knowledge graphs are merged to obtain a second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between each conventional test case; Execute each conventional test case to obtain a corresponding execution result, and supplement the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph; Obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
2. The method according to claim 1, characterized in that The step of obtaining the first dependency relationship between the conventional test cases in the conventional test case set of each database basic function type includes: The input, output and functions of any two regular test cases are analyzed. If at least one of the functional flow dependency, input-output association, functional coverage, precondition and postcondition relationship and functional logic and business process relationship exists between the any two regular test cases, it is determined that there is a first dependency relationship between the any two regular test cases.
3. The method according to claim 1, characterized in that The method further comprises: For any two regular test cases, if there exists at least one of the relationship between database table structure and constraint conditions, foreign key association relationship between database tables, relationship between index and query performance, and database transaction management between the any two regular test cases, it is determined that there is a second dependency relationship between the any two regular test cases.
4. The method according to claim 1 or 3, characterized in that: The second dependency relationship between the conventional test cases in the conventional test set based on the multiple database basic function types is used to fuse the first test case knowledge graphs to obtain the second test case knowledge graph, including: The conventional test cases corresponding to each second dependency are the head entity and the tail entity respectively, and the second dependency is the entity relationship, and the corresponding test case triples are constructed; Perform business logic verification on each triple, delete the test case triples that fail the logic verification, retain the test case triples that pass the logic verification, and merge the retained test case triples with each first test case knowledge graph to obtain the second test case knowledge graph.
5. The method according to claim 1, characterized in that The respectively executing each conventional test case to obtain a corresponding execution result, and supplementing the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph, including: For any conventional test case, obtaining a first dependency relationship between an execution result of the conventional test case and another conventional test case in the triplet where the conventional test case is located; wherein the execution result includes success or failure; Taking the execution result as the head entity, taking the other conventional test case as the tail entity, and taking the corresponding first dependency relationship as the entity relationship, constructing a corresponding triple; The triples corresponding to each execution result are added to the second test case knowledge graph to obtain the third test case knowledge graph.
6. The method according to claim 1, characterized in that The obtaining of the specification text of at least one target business scenario, searching the third test case knowledge graph based on the specification text of each target business scenario, and obtaining the test case relationship chain corresponding to the target business scenario includes: For any target business scenario, semantic analysis and keyword extraction are performed on the specification text of the target business scenario to obtain result words, wherein the result words include test case indicator words and dependency indicator words; Locating at least one starting test case in the third test case knowledge graph based on the test case indicator, and then determining subsequent test cases of each starting test case according to the dependency indicator to obtain a corresponding initial test case relationship chain; Based on each initial test case relationship chain, the test case relationship chain is determined.
7. The method according to claim 6, characterized in that The step of determining the test case relationship chain based on each initial test case relationship chain includes: The input of each initial test case relationship chain is compared with the input of the target business scenario, the output of each initial test case relationship chain is compared with the output of the target business scenario, and the initial test cases in each initial test case relationship chain whose input and output match the input and output of the target business scenario are determined as the test case relationship chain of the target business scenario.
8. A software test driven code generation device, characterized in that: include: A conventional test case set acquisition module is used to acquire, for a database to be written, a plurality of conventional test case sets corresponding to the database to be written, and each conventional test case set corresponds to a database basic function type; A first test case knowledge graph acquisition module is used to acquire a first dependency relationship between each conventional test case in a conventional test case set of each database basic function type, and to construct a first test case knowledge graph by taking each conventional test case as an entity and the first dependency relationship between each conventional test case as an entity relationship; wherein the first dependency relationship indicates a call relationship between each conventional test case; A second test case knowledge graph acquisition module is used to fuse the first test case knowledge graphs based on the second dependency relationship between the conventional test cases in the conventional test sets of the multiple database basic function types to obtain a second test case knowledge graph; wherein the second dependency relationship indicates the calling relationship between the database design elements between the conventional test cases; A third test case knowledge graph acquisition module is used to execute each conventional test case to obtain a corresponding execution result, and to supplement the second test case knowledge graph based on each execution result to obtain a third test case knowledge graph; An integrated test case acquisition module is used to obtain the specification text of at least one target business scenario, search the third test case knowledge graph based on the specification text of each target business scenario, obtain the test case relationship chain corresponding to the target business scenario, and generate an integrated test case corresponding to the target business scenario based on the test case relationship chain.
9. An electronic 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 program, the method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
