Code test case generation method, system and equipment and storage medium

Through automated methods, different code, call chain relationship library and use case association library are used to generate test cases, which solves the problem of cumbersome manual creation of test cases in the existing technology, and realizes efficient and accurate test case generation, improving software quality and delivery efficiency.

CN120104471APending Publication Date: 2025-06-06GUANGZHOU BAIGUOYUAN INFORMATION TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510095409.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

In the prior art, the creation and maintenance of software test cases rely on cumbersome and time-consuming manual processes, resulting in extended testing cycles, reduced development efficiency, unable to respond quickly to code changes, and unable to effectively cover all related modified code tests.

Method used

By obtaining the differential code between the new branch code and the benchmark branch code, querying the pre-built code call chain relationship library and use case association library, determining the target call chain relationship and target use cases, and building test cases for different code to achieve automated test case generation.

Benefits of technology

It realizes accurate and efficient generation of test cases, avoids the cumbersome process of manual creation and maintenance, and improves software quality and delivery efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120104471A_ABST
    Figure CN120104471A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a code test case generation method and system, equipment and a storage medium. According to the technical scheme provided by the embodiment of the invention, the difference code between the new branch code and the reference branch code is determined by obtaining the new branch code; querying a pre-constructed code call chain relationship library based on the difference code, determining matched call chain relationship information as a target call chain relationship, querying a pre-constructed code case association library based on the difference code, and determining matched case information as a target case; and constructing a test case of the difference code based on the target call chain relationship and the target case, so as to perform code testing of the difference code based on the test case. By adopting the technical means, accurate and efficient construction of the difference code test case can be realized, and the generation efficiency of the test case is improved while the accuracy of the test case is guaranteed. Tedious processes of manual use case creation and maintenance are avoided, so that the software quality and the delivery efficiency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, system, device and storage medium for generating code test cases. Background Art

[0002] At present, with the rapid development of software development environment, in order to ensure that the quality, function and performance of software meet the expected requirements, the frequent iteration of software products requires the use of corresponding test cases for software testing. When conducting software testing, testers need to build test cases based on the code to be tested. The test cases include a set of test inputs, expected outputs and execution conditions of the code to be tested to verify whether the code to be tested works as expected. Then, by collecting the test results (such as coverage data) of the code to be tested and analyzing them, code errors and defects can be determined.

[0003] However, relevant code testing solutions often rely on cumbersome and time-consuming manual use case creation and maintenance methods. Manual creation of test cases will significantly extend the test cycle and reduce development efficiency. When the code changes, it is difficult to quickly and accurately respond to the test, and it is impossible to effectively cover all relevant modified code tests, resulting in relatively low software quality and delivery efficiency during the rapid software iteration process. Summary of the invention

[0004] The embodiments of the present application provide a code test case generation method, system, device and storage medium, which can automatically generate code test cases, ensure the accuracy of test cases, and at the same time improve the efficiency of test case generation, thereby solving the technical problem of cumbersome and time-consuming manual test case construction process.

[0005] In a first aspect, an embodiment of the present application provides a method for generating a code test case, comprising:

[0006] Obtain the new branch code and determine the difference code between the new branch code and the baseline branch code;

[0007] Based on the difference code query, the pre-built code call chain relationship library is determined to be the target call chain relationship. Based on the difference code query, the pre-built code use case association library is determined to be the target use case. The call chain relationship information is pre-built based on the method call records in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library. The use case information is pre-built based on the use case operation records in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library.

[0008] A test case of the difference code is constructed based on the target call chain relationship and the target use case, so as to perform code testing of the difference code based on the test case.

[0009] In a second aspect, an embodiment of the present application provides a code test case generation system, comprising:

[0010] a difference determination module, configured to obtain a new branch code and determine a difference code between the new branch code and a reference branch code;

[0011] A query module is configured to query a pre-built code call chain relationship library based on the difference code, determine the matching call chain relationship information as the target call chain relationship, query a pre-built code use case association library based on the difference code, determine the matching use case information as the target use case, the call chain relationship information is pre-built based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library, the use case information is pre-built based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library;

[0012] The use case building module is configured to build a test case of the difference code based on the target call chain relationship and the target use case, so as to perform code testing of the difference code based on the test case.

[0013] In a third aspect, an embodiment of the present application provides a code test case generation device, including:

[0014] memory and one or more processors;

[0015] The memory is configured to store one or more programs;

[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement the code test case generating method as described in the first aspect.

[0017] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions, when executed by a computer processor, are configured to execute the code test case generation method as described in the first aspect.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes instructions. When the instructions are executed on a computer or a processor, the computer or the processor executes the code test case generation method as described in the first aspect.

[0019] The embodiment of the present application obtains the new branch code to determine the difference code between the new branch code and the benchmark branch code; based on the difference code, the pre-constructed code call chain relationship library is queried to determine the matching call chain relationship information as the target call chain relationship; based on the difference code, the pre-constructed code use case association library is queried to determine the matching use case information as the target use case; the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library; the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library; based on the target call chain relationship and the target use case, a test case for the difference code is constructed, so as to perform code testing of the difference code based on the test case. The above technical means are adopted to determine the difference code between the new branch code and the benchmark branch code, query the pre-constructed code call chain relationship library and the code use case association library based on the difference code, and then construct the test case for the difference code based on the queried target call chain relationship and the target use case, so as to realize the accurate and efficient construction of the difference code test case, and improve the generation efficiency of the test case while ensuring the accuracy of the test case. Avoid the tedious process of manual use case creation and maintenance, thereby improving software quality and delivery efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 It is a flowchart of a code test case generation method provided by an embodiment of the present application;

[0021] Figure 2 It is a flow chart of the generation and application of test cases in the embodiment of the present application;

[0022] Figure 3 It is a flow chart of generating a method call record in an embodiment of the present application;

[0023] Figure 4 is a flowchart of use case information generation in an embodiment of the present application;

[0024] Figure 5 It is a structural diagram of a code test case generation system provided in an embodiment of the present application;

[0025] Figure 6 It is a structural diagram of a code test case generating device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical scheme and advantages of the present application clearer, the specific embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. It is understood that the specific embodiments described herein are only used to explain the present application, rather than to limit the present application. It should also be noted that, for the convenience of description, only the part related to the present application but not all the contents are shown in the accompanying drawings. Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow chart describes each operation (or step) as a sequential process, many of the operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. The process can be terminated when its operation is completed, but it can also have additional steps not included in the accompanying drawings. The process can correspond to a method, a function, a procedure, a subroutine, a subprogram, etc.

[0027] The code test case generation method provided in this application aims to determine the difference code between the new branch code and the benchmark branch code, query the pre-built code call chain relationship library and code case association library based on the difference code, and then build the test case of the difference code based on the queried target call chain relationship and target case, so as to realize the accurate and efficient construction of the difference code test case.

[0028] With the rapid development of the software development environment, the frequent iteration of product requirements has put forward higher requirements on the team's response speed. This change has brought tremendous pressure to traditional testing methods, especially in ensuring a balance between efficient testing process and high-quality delivery. At present, the huge amount of software code and complex calling relationships make traditional testing often rely on cumbersome and time-consuming manual use case creation and maintenance methods, which significantly prolongs the testing cycle and reduces development efficiency. At the same time, the test strategy of manual use case creation and maintenance lacks accurate response capabilities when facing code changes, and cannot effectively cover all related modifications, resulting in severe challenges to software quality and delivery efficiency during rapid iteration.

[0029] Although some methods rely on basic coverage analysis to create use cases, they lack in-depth analysis of complex call relationships and dynamic code structures, which may lead to failure to identify potential code impacts. In addition, these systems still require manual intervention when updating data and recommending use cases. The overall process automation level is insufficient, and the use case generation efficiency is low.

[0030] In order to cope with this situation, automatically generating test cases closely related to code changes has become an effective method. Based on this, a code test case generation method of an embodiment of the present application is provided to solve the technical problem of cumbersome and time-consuming manual construction of test case processes. Through in-depth analysis of code and operation behavior, accurate binding of use cases and codes is achieved, which not only helps to quickly generate test cases, but also helps to select the best test case set at low cost, effectively shortens test preparation time, reduces unnecessary regression testing costs, and helps development teams iterate products more efficiently and flexibly respond to market demand.

[0031] Example:

[0032] Figure 1 A flowchart of a code test case generation method provided in an embodiment of the present application is given. The code test case generation method provided in this embodiment can be executed by a code test case generation device, which can be implemented by software and / or hardware. The code test case generation device can be composed of two or more physical entities, or can be composed of one physical entity. Generally speaking, the code test case generation device can be a processing device such as a case generation server and a code test device.

[0033] The following description is made by taking the code test case generation device as an example of the subject of the code test case generation method. Figure 1 , the code test case generation method specifically includes:

[0034] S110: Obtain a new branch code, and determine a difference code between the new branch code and the reference branch code.

[0035] When generating code test cases, this application pre-builds the binding relationship between the code and the call chain relationship information and the use case information. Therefore, when the code is changed, the difference code between the new branch code and the baseline branch code is determined, and then the multi-level call relationship and use case information are deeply analyzed according to the query code to generate accurate and comprehensive test cases.

[0036] Among them, refer to Figure 2 When a test case needs to be generated, the new branch code of the software project is first obtained. The new branch code is completed through the version control system (Git), which can be used to track changes in computer files. Then, by comparing the new branch code with the baseline branch code (usually the main branch code or the previous stable version branch corresponding to the new branch code), the difference code between the two is identified. The difference code may include newly added functions, modified functions, deleted functions, etc.

[0037] Exemplarily, take the software testing of Android client and Java background service as an example. By real-time monitoring of new branch code in the relevant system, when the software code changes (i.e., the new version of the new branch code) is detected, the execution case generation task is automatically triggered, and the system generates test cases based on the code test case generation method of this application. Among them, by monitoring the daily software automation packaging tasks, and after generating a new package, the execution case generation task is automatically triggered, the difference between the new branch code and the benchmark branch code is compared, and the version control system is used for differential comparison, and the changed code class and line information are extracted from it, which is defined as the difference code.

[0038] S120. Query the pre-built code call chain relationship library based on the difference code, determine the matching call chain relationship information as the target call chain relationship, query the pre-built code use case association library based on the difference code, determine the matching use case information as the target use case, the call chain relationship information is pre-built based on the method call records in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library, the use case information is pre-built based on the use case operation records in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library.

[0039] Based on the difference code determined above, the code call chain relationship library and the code use case association library are queried respectively to determine the call chain relationship information and use case information required for test case generation using the difference code, which are defined as target call chain relationship and target use case.

[0040] Among them, the code call chain relationship library is pre-built, which stores the method call records during the historical code data testing process. These records describe the call relationship between different code elements (such as functions, classes, etc.). By querying this library, the call chain relationship information matching the difference code can be found.

[0041] The code case association library is also pre-built, which stores the case operation records during the historical code data testing process. These records associate specific test cases with the code parts they cover. The system queries this library to find the historical test case information related to the difference code.

[0042] Based on the above code call chain relationship library and code use case association library, the call chain relationship information and use case information matching the difference code can be queried. According to actual needs, during the query process, the code match can be a complete match, or based on the set similarity comparison rules, when the code and historical code data match to a set threshold, the two are determined to match.

[0043] Optionally, before querying the pre-built code call chain relationship library based on the difference code, it also includes:

[0044] During the historical code data testing process, the method call records of the historical code data are determined based on the bytecode operation framework, the method call records are bound to the current historical code data to generate call chain relationship information, and the call chain relationship information is stored in the code call chain relationship library.

[0045] Bytecode manipulation frameworks (such as ASM) allow developers to programmatically read, modify, and generate bytecode in bytecode-based languages ​​such as Java. These frameworks usually provide rich APIs to access and manipulate bytecode-level structures such as classes, methods, and fields. Before testing historical code data, use the bytecode manipulation framework to instrument historical code. Instrumentation refers to inserting additional instructions or code segments into bytecode to collect runtime information. When a method is called, the instrumentation code records the call information. During the test run, the instrumented historical code data is executed, and method calls are triggered by running test cases or simulating user operations. During the method call process, the instrumentation code captures and records the method call records. The collected method call records are then parsed and processed to extract useful information, such as method name, class name, call order, etc. Based on the parsed method call records, a call chain relationship can be constructed. The constructed call chain relationship information is then bound to the current historical code data and stored in the code call chain relationship library.

[0046] Through the above process, the system can automatically collect method call records during the historical code data testing process and generate call chain relationship information. This information is stored in the code call chain relationship library for subsequent query and use. This provides strong support for the generation of automated test cases.

[0047] Specifically, refer to Figure 3 , based on the bytecode operation framework, determine the method call records of historical code data, including:

[0048] S1201, query the operation code of the method executed during the historical code data test process based on the method access class of the bytecode operation framework;

[0049] S1202: When the operation code belongs to a method operation type, the calling relationship, inheritance relationship and implementation interface list of the currently executed method are recorded as a method calling record.

[0050] Exemplarily, in both Android client and Java background service, the ASM framework can be used to obtain method call relations, parent classes of loaded classes, and lists of interfaces implemented by them. In MethodVisitor (method access class), by rewriting the visitMethodInsn method, when the operation code is judged to be a method operation type, information such as the call relations of the current loaded method is recorded. Data such as call relations, inheritance relations, and implementation interface lists are automatically reported each time a build is made. Thus, during the execution of historical code data, method call records are obtained by receiving data such as corresponding call relations, inheritance relations, and corresponding implementation interface lists. Then the method call records are stored in the code call chain relationship library for subsequent query calls.

[0051] On the other hand, referring to Figure 4 , before querying the pre-built code call chain relationship library based on the difference code, it also includes:

[0052] S1203. During the historical code data testing process, the historical code coverage data during the execution of the historical code data is recorded based on the stub code of the historical code data, where the historical code coverage data includes the class name, line number, and execution time of the historical code data execution;

[0053] S1204, performing a use case test of the historical code data based on the pre-configured instrumentation package of the historical code data, and generating a use case operation record;

[0054] S1205. Bind the historical code coverage data with the use case operation record to generate use case information, and store the use case information in a code use case association library.

[0055] Before testing historical code data, you only need to configure the instrumentation plug-in or instrumentation JAR package for the historical code data corresponding to the Android client and the Java background service respectively. The system will automatically handle the code instrumentation of the historical code data to be tested each time it is built. Among them, in the ASM framework, ClassVisitor (visitor class) and MethodVisitor (method visit class) are two core classes used to traverse and modify classes and methods in Java bytecode files. In the Android client, you can rewrite the visitLineNumber (visit line number) method in MethodVisitor to obtain the line number information of the code. At the same time, by calling the visitMethodInsn method, a method call instruction is inserted into each executable code line; in the Java background service, ASM can also insert method call instructions when the class is loaded and each line of the method is accessed by implementing the ClassFileTransformer (class file encoder) interface in the Java Instrumentation API. These inserted instructions will record the executed class, line number, coverage time, project data and other information when the program is running, and make regular reports.

[0056] Later, during the execution of the instrumentation package for historical code data testing, coverage information is automatically reported regularly to ensure the real-time nature of relevant data. When the instrumentation package is running, the computing backend stores the received coverage data in the database. The data structure includes the class name, line number, execution time, etc. of the covered code, and historical code coverage data is obtained for subsequent data processing and analysis.

[0057] Furthermore, on the Android client, the system uses the instrumentation package to test the application; on the Java server, the test is performed in the started instrumented environment. After the tester performs the specified test operation, the status of the corresponding use case is changed, and the use case platform automatically reports the operation status data with a timestamp to facilitate the subsequent association of the use case with the code, thereby generating a use case operation record.

[0058] The computing background periodically monitors the unprocessed coverage data. According to the time range of the use case operation and the code coverage time, the system divides the code coverage data into specific time periods of the corresponding requirements or branches, thereby establishing an association between the use case and the code, and storing the use case information in the code use case association library.

[0059] After binding the historical code coverage data and the use case operation records to the code use case association library, it also includes:

[0060] Based on at least one of preset public class cleaning information, batch operation cleaning information, expired dirty data cleaning information, multi-branch binding cleaning information and invalid use case cleaning information, data cleaning is performed on the use case information of the code use case association library.

[0061] By cleaning the code use case association library, accurate use case information can be generated. Cleaning strategies include but are not limited to the following aspects: public class cleaning, batch operation cleaning, expired dirty data cleaning, multi-branch binding cleaning, invalid use case cleaning, etc.

[0062] For the cleaning of the use case-code relationship library, different cleaning strategy combinations are mainly used for screening and recommendation. In practical applications, the cleaning of use cases can also use machine learning algorithms to learn and identify patterns from historical data to optimize the cleaning process. Machine learning algorithms can also enable the system to dynamically adapt to changing environments and requirements, improving the accuracy and reliability of subsequent test case generation.

[0063] Flexible data cleaning and intelligent association strategies can effectively remove dirty data caused by human operations, redundant and outdated information, ensure that the binding relationship between code and use cases in the code use case association library always maintains high credibility and high value, and ensure the accuracy of subsequent use case recommendations.

[0064] Based on the above pre-built code call chain relationship library and code use case association library, the corresponding target call chain relationship and target use case can be matched by comparing the difference code with the historical code test data.

[0065] Among them, according to the difference code, Git is used to compare the code use case association library, and the changed lines of the difference code are mapped to the corresponding lines in the code use case association library, so as to obtain the use case information of the corresponding line, that is, the target use case. Similarly, according to the difference code, Git is used to compare the relevant classes in the code call chain relationship library, and the changed lines of the difference code are mapped to the corresponding call chain lines to obtain the corresponding method, and then the caller of the method is further queried, the inheritance hierarchy of the changed class and the implemented interface are analyzed, and all relevant call chain relationship information, that is, the target call chain relationship, is recursively searched.

[0066] S130: Construct a test case for the difference code based on the target call chain relationship and the target use case, so as to perform code testing on the difference code based on the test case.

[0067] Finally, by combining the information obtained from the code call chain relationship library and the code case association library, test cases for the difference code can be automatically generated. Test cases may include input data, expected output, and execution conditions. Based on a clear target case, the above input data, expected output, and execution conditions can be obtained. Based on the target call chain relationship, the relevant method call information when the test case is executed can be clarified. Therefore, the two are combined, and the corresponding test case construction template is used to input the target call chain relationship and the target case to generate the final test case for the difference code.

[0068] Among them, the test cases of differential code are constructed based on the target call chain relationship and target use case, including:

[0069] Generate initial test case information based on target call chain relationship and target test case;

[0070] The pre-built multi-dimensional test case database is queried based on the difference code, the initial test case information is adjusted based on the query results, and the test case of the difference code is generated.

[0071] This application supports simultaneous querying of multi-dimensional use case databases such as the full code binding knowledge base, incremental code binding knowledge base, and different cleaning strategy knowledge bases to provide multi-dimensional use case recommendation data. Based on the relevant use case data queried, the initial test case information is adaptively adjusted and modified to obtain the final differential code test case.

[0072] By combining the full and incremental code binding knowledge base, a variety of test case generation methods with different strategies are provided, enabling the test team to quickly generate relevant optimal test cases for different code changes, requirements and scenarios.

[0073] Optionally, after building a test case of the difference code based on the target call chain relationship and the target use case, it also includes:

[0074] Output the test cases to the test case platform for recommendation and display, or trigger the test case test of the difference code based on the test cases and output the corresponding test results.

[0075] Exemplarily, based on the above test case recommendation method, during the test preparation stage of the code, the test cases for the corresponding difference codes are determined by inputting new branch codes. Users can easily view recommended test cases related to code requirements and code changes. At the same time, the system can automatically generate recommended automated test cases based on any new branch code submission, and combine with the automation platform to automatically execute the corresponding test scripts, and finally provide test results for viewing, thereby improving test quality and efficiency.

[0076] It should be noted that in scenarios such as iOS mobile application development, Web application development, game development, electronic products or embedded system development, this application can be used to achieve accurate binding of code with different data scenarios, and test cases can also be generated based on the binding results and changes to ensure that projects and products maintain high quality and stability in a rapidly changing market environment.

[0077] In the above, by obtaining the new branch code, the difference code between the new branch code and the benchmark branch code is determined; based on the difference code, the pre-constructed code call chain relationship library is queried to determine the matching call chain relationship information as the target call chain relationship; based on the difference code, the pre-constructed code use case association library is queried to determine the matching use case information as the target use case; the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library; the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library; based on the target call chain relationship and the target use case, a test case for the difference code is constructed, so as to perform code testing of the difference code based on the test case. By adopting the above technical means, by determining the difference code between the new branch code and the benchmark branch code, the pre-constructed code call chain relationship library and the code use case association library are queried based on the difference code, and then the test case for the difference code is constructed based on the queried target call chain relationship and the target use case, so as to realize the accurate and efficient construction of the difference code test case, while ensuring the accuracy of the test case, the generation efficiency of the test case is improved. Avoid the tedious process of manual use case creation and maintenance, thereby improving software quality and delivery efficiency.

[0078] Based on the above embodiments, Figure 5 A schematic diagram of the structure of a code test case generation system provided for this application. Figure 5 The code test case generation system provided in this embodiment specifically includes: a difference determination module 31, a query module 32 and a use case construction module 33.

[0079] The difference determination module 31 is configured to obtain a new branch code and determine a difference code between the new branch code and the reference branch code;

[0080] The query module 32 is configured to query the pre-constructed code call chain relationship library based on the difference code, determine the matching call chain relationship information as the target call chain relationship, query the pre-constructed code use case association library based on the difference code, determine the matching use case information as the target use case, the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library, the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library;

[0081] The use case construction module 33 is configured to construct a test case of the difference code based on the target call chain relationship and the target use case, so as to perform code testing of the difference code based on the test case.

[0082] Specifically, before querying the pre-built code call chain relationship library based on the difference code, it also includes:

[0083] During the historical code data testing process, the method call records of the historical code data are determined based on the bytecode operation framework, the method call records are bound to the current historical code data to generate call chain relationship information, and the call chain relationship information is stored in the code call chain relationship library.

[0084] Determine the method call records of historical code data based on the bytecode operation framework, including:

[0085] Method access class based on bytecode operation framework queries the operation code of the method executed during the historical code data test;

[0086] When the operation code belongs to the method operation type, the calling relationship, inheritance relationship and implementation interface list of the currently executed method are recorded as the method calling record.

[0087] Specifically, before querying the pre-built code call chain relationship library based on the difference code, it also includes:

[0088] During the historical code data testing process, the historical code coverage data during the execution of the historical code data is recorded based on the instrumentation code of the historical code data. The historical code coverage data includes the class name, line number and execution time of the historical code data execution;

[0089] Perform use case tests on historical code data based on the pre-configured instrumentation package for historical code data and generate use case operation records;

[0090] Bind historical code coverage data with use case operation records to generate use case information, and store the use case information in the code use case association library.

[0091] After binding the historical code coverage data and the use case operation records to the code use case association library, it also includes:

[0092] Based on at least one of preset public class cleaning information, batch operation cleaning information, expired dirty data cleaning information, multi-branch binding cleaning information and invalid use case cleaning information, data cleaning is performed on the use case information of the code use case association library.

[0093] Specifically, the test cases of the difference codes are constructed based on the target call chain relationship and the target use case, including:

[0094] Generate initial test case information based on target call chain relationship and target test case;

[0095] The pre-built multi-dimensional test case database is queried based on the difference code, the initial test case information is adjusted based on the query results, and the test case of the difference code is generated.

[0096] After building the test cases of the difference code based on the target call chain relationship and target use case, it also includes:

[0097] Output the test cases to the test case platform for recommendation and display, or trigger the test case test of the difference code based on the test cases and output the corresponding test results.

[0098] In the above, by obtaining the new branch code, the difference code between the new branch code and the benchmark branch code is determined; based on the difference code, the pre-constructed code call chain relationship library is queried to determine the matching call chain relationship information as the target call chain relationship; based on the difference code, the pre-constructed code use case association library is queried to determine the matching use case information as the target use case; the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library; the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library; based on the target call chain relationship and the target use case, a test case for the difference code is constructed, so as to perform code testing of the difference code based on the test case. By adopting the above technical means, by determining the difference code between the new branch code and the benchmark branch code, the pre-constructed code call chain relationship library and the code use case association library are queried based on the difference code, and then the test case for the difference code is constructed based on the queried target call chain relationship and the target use case, so as to realize the accurate and efficient construction of the difference code test case, while ensuring the accuracy of the test case, the generation efficiency of the test case is improved. Avoid the tedious process of manual use case creation and maintenance, thereby improving software quality and delivery efficiency.

[0099] The code test case generation system provided in the embodiment of the present application can be configured to execute the code test case generation method provided in the above embodiment, and has corresponding functions and beneficial effects.

[0100] Based on the above practical example, the present application embodiment also provides a code test case generation device, referring to Figure 6 , the code test case generation device includes: a processor 31, a memory 32, a communication module 33, an input device 34 and an output device 35. The memory, as a computer-readable storage medium, can be configured to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the code test case generation method described in any embodiment of the present application (for example, a difference determination module, a query module and a case construction module in the code test case generation system). The communication module is configured to perform data transmission. The processor executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory, that is, the above-mentioned code test case generation method is realized. The input device can be configured to receive input digital or character information, and generate key signal input related to the user settings and function control of the device. The output device may include a display device such as a display screen. The code test case generation device provided above can be configured to execute the code test case generation method provided in the above embodiment, and has corresponding functions and beneficial effects.

[0101] On the basis of the above embodiments, the embodiments of the present application further provide a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores computer-executable instructions, wherein the computer-executable instructions are configured to execute a code test case generation method when executed by a computer processor, and the storage medium may be any of various types of memory devices or storage devices. Of course, the non-volatile computer-readable storage medium provided in the embodiments of the present application, whose computer-executable instructions are not limited to the code test case generation method described above, may also execute the related operations in the code test case generation method provided in any embodiment of the present application.

[0102] On the basis of the above embodiments, the embodiments of the present application also provide a computer program product. The essence of the technical solution of the present application or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer program product is stored in a storage medium, including a number of instructions for enabling a computer device, a mobile terminal or a processor therein to execute all or part of the steps of the code test case generation method described in each embodiment of the present application.

Claims

1. A method for generating code test cases, characterized in that: include: Obtaining a new branch code, and determining a difference code between the new branch code and a reference branch code; Based on the difference code, a pre-constructed code call chain relationship library is queried to determine that the matching call chain relationship information is the target call chain relationship; based on the difference code, a pre-constructed code use case association library is queried to determine that the matching use case information is the target use case; the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library; the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library; A test case for the difference code is constructed based on the target call chain relationship and the target use case, so as to perform code testing on the difference code based on the test case.

2. The code test case generation method according to claim 1, characterized in that: Before querying the pre-built code call chain relationship library based on the difference code, the method further includes: During the historical code data testing process, the method call record of the historical code data is determined based on the bytecode operation framework, the method call record is bound to the current historical code data to generate the call chain relationship information, and the call chain relationship information is stored in the code call chain relationship library.

3. The code test case generation method according to claim 2, characterized in that: The method call record of determining historical code data based on the bytecode operation framework includes: Method access class based on bytecode operation framework queries the operation code of the method executed during the historical code data test; In the case where the operation code belongs to a method operation type, the calling relationship, inheritance relationship and implementation interface list of the currently executed method are recorded as a method calling record.

4. The code test case generation method according to claim 1, characterized in that: Before querying the pre-built code call chain relationship library based on the difference code, the method further includes: During the historical code data testing process, the historical code coverage data during the execution of the historical code data is recorded based on the stub code of the historical code data, wherein the historical code coverage data includes the class name, line number and execution time of the historical code data execution; Perform use case tests on historical code data based on the pre-configured instrumentation package for historical code data and generate use case operation records; The historical code coverage data is bound to the use case operation record to generate the use case information, and the use case information is stored in the code use case association library.

5. The method for generating code test cases according to claim 4, characterized in that: After the historical code coverage data and the use case operation record are bound and stored in the code use case association library, the method further includes: Based on at least one of preset common class cleaning information, batch operation cleaning information, expired dirty data cleaning information, multi-branch binding cleaning information and invalid use case cleaning information, data cleaning is performed on the use case information of the code use case association library.

6. The method for generating code test cases according to any one of claims 1 to 5, characterized in that: The step of constructing a test case for the difference code based on the target call chain relationship and the target use case includes: Generate initial test case information based on the target call chain relationship and the target test case; A pre-constructed multi-dimensional test case database is queried based on the difference code, the initial test case information is adjusted based on the query result, and a test case for the difference code is generated.

7. The method for generating code test cases according to any one of claims 1 to 5, characterized in that: After constructing the test case of the difference code based on the target call chain relationship and the target use case, it also includes: The test case is output to the use case platform for recommendation and display, or a use case test of the difference code is triggered based on the test case, and the corresponding test result is output.

8. A code test case generation system, characterized in that: include: a difference determination module, configured to obtain a new branch code and determine a difference code between the new branch code and a reference branch code; A query module is configured to query a pre-constructed code call chain relationship library based on the difference code, determine that the matching call chain relationship information is a target call chain relationship, query a pre-constructed code use case association library based on the difference code, determine that the matching use case information is a target use case, the call chain relationship information is pre-constructed based on the method call record in the historical code data testing process, and is bound with the corresponding historical code data and stored in the code call chain relationship library, the use case information is pre-constructed based on the use case operation record in the historical code data testing process, and is bound with the corresponding historical code coverage data and stored in the code use case association library; A use case construction module is configured to construct a test case of the difference code based on the target call chain relationship and the target use case, so as to perform code testing of the difference code based on the test case.

9. A code test case generating device, characterized in that: include: memory and one or more processors; The memory is configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the code test case generation method as described in any one of claims 1-7.

10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a computer processor, they are configured to execute the code test case generation method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The computer program product includes instructions, and when the instructions are executed on a computer or a processor, the computer or the processor executes the code test case generating method as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Test case recommendation method, system and equipment

    CN121658388A

  • A financial software testing method, device and equipment based on multi-source heterogeneous data chain fusion and a medium

    CN122527027A