Software code case generation method and device, storage medium and electronic equipment

By detecting and filtering the test parameters of the reference use case collection and generating the target use case collection, the problem of low test case generation efficiency is solved and more efficient test path coverage and quality improvement is achieved.

CN120256316AActive Publication Date: 2025-07-04INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202510728898.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-03
Publication Date
2025-07-04
Estimated Expiration
2045-06-03

AI Technical Summary

Technical Problem

In the prior art, the generation efficiency of test cases is low, manual writing of test cases is low, and boundary conditions are easily missed. Traditional testing tools cannot analyze the trigger conditions that do not cover the code, resulting in difficulty in optimizing test cases and difficulty in improving code coverage.

Method used

By detecting the test parameters of the reference use case collection to the software code, select candidate use cases that contribute greatly to the test coverage, and adjust the reference use case collection based on the test path of the candidate use case, generate the target use case collection, and automatically identify effective test cases and optimize the test path.

Benefits of technology

It improves the generation efficiency of test cases, ensures that test cases cover code paths more effectively, dynamically adapt to different scenarios, and improves test quality and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256316A_ABST
    Figure CN120256316A_ABST
Patent Text Reader

Abstract

The invention discloses a software code case generation method and device, a storage medium and electronic equipment, and relates to the technical field of computers.The software code case generation method comprises the steps that testing parameters of a reference case set for software codes are detected, and different reference cases in the reference case set are used for testing different code paths of the software codes; according to the characteristic that different reference cases have different contribution degrees to the test coverage rate of the software code due to the fact that the test coverage rate of the software code is different, candidate cases with the contribution degrees to the test coverage rate larger than a target contribution degree are screened out from a reference case set, and then target code paths tested by the candidate cases are obtained; according to the method, the reference case set is adjusted with the aim of increasing the association degree between the code path tested by the test case in the reference case set and the target code path, the target case set is obtained, the technical problems that the generation efficiency of the test case is low and the like are solved, and the technical effect of improving the generation efficiency of the test case is achieved.
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 computers, and in particular, to a method and device for generating use cases of software code, a storage medium, and an electronic device. Background Art

[0002] In the related art, when testing the integrity and effectiveness of software code, usually, a test engineer manually designs test cases according to the logic of the code to be tested, and then uses a test tool (such as Sonar, JaCoCo, Istanbul, etc.) to count the code coverage rate of the code to be tested during the execution of the test cases, that is, the proportion of the code to be tested that is covered.

[0003] However, the traditional testing method has limitations. On the one hand, the efficiency of manually writing test cases is low, it is easy to miss boundary cases, and when facing a large-scale code library, it is difficult for humans to identify complex logic branches and hidden execution paths in the code. On the other hand, traditional test tools can only count coverage data and cannot deeply analyze the coverage results to actively identify the reasons why the test code is not covered. In addition, the manually designed test cases have poor applicability and lack the ability to adapt to different business scenarios and code patterns. For example, for two quite different business scenarios such as an e-commerce system and a medical system, it is very difficult to directly reuse the manually designed test cases, and a large amount of modification and re-design are required, resulting in an extended test cycle. Therefore, in the testing of software code, the low efficiency of manually writing test cases and the functional limitations of traditional test tools hinder the optimization process of test cases, making it difficult to improve the code coverage rate, and thus resulting in low testing efficiency of software code.

[0004] In the related art, no effective solution has been proposed for technical problems such as low generation efficiency of test cases. Summary of the Invention

[0005] The embodiments of the present application provide a method and device for generating use cases of software code, a storage medium, and an electronic device, so as to at least solve the technical problems such as low generation efficiency of test cases in the related art.

[0006] According to an embodiment of the embodiments of the present application, a method for generating use cases of software code is provided, including:

[0007] Detecting test parameters of software code by a reference use case set, where each reference use case in the reference use case set is used to test a part of the code path of the software code, and the test parameters are used to indicate the contribution degree of each reference use case to the test coverage rate of the software code;

[0008] Select candidate test cases from the reference test case set whose test parameters meet the parameter conditions, where the contribution degree of the test cases whose test parameters meet the parameter conditions to the test coverage rate is greater than the target contribution degree;

[0009] Obtain the target code path tested by the candidate test cases;

[0010] Adjust the reference test case set according to the target code path to obtain a target test case set, where the correlation degree between the code paths tested by the target test case set and the target code path is greater than the correlation degree between the code paths tested by the reference test case set and the target code path.

[0011] According to another embodiment of the embodiments of the present application, there is also provided a device for generating test cases for software code, including:

[0012] A detection module, configured to detect the test parameters of the reference test case set for the software code, where each reference test case in the reference test case set is used to test a partial code path of the software code, and the test parameters are used to indicate the contribution degree of each reference test case to the test coverage rate of the software code;

[0013] A screening module, configured to screen candidate test cases whose test parameters meet the parameter conditions from the reference test case set, where the contribution degree of the test cases whose test parameters meet the parameter conditions to the test coverage rate is greater than the target contribution degree;

[0014] A first obtaining module, configured to obtain the target code path tested by the candidate test cases;

[0015] An adjustment module, configured to adjust the reference test case set according to the target code path to obtain a target test case set, where the correlation degree between the code paths tested by the target test case set and the target code path is greater than the correlation degree between the code paths tested by the reference test case set and the target code path.

[0016] The present application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any one of the above methods for generating test cases for software code when executing the computer program.

[0017] The present application also provides a computer-readable storage medium, in which a computer program is stored, where the computer program implements the steps of any one of the above methods for generating test cases for software code when being executed by a processor.

[0018] The present application also provides a computer program product, including a computer program, where the computer program implements the steps of any one of the above methods for generating test cases for software code when being executed by a processor.

[0019] Through this application, by detecting the test parameters of the software code against the reference test case set, and taking advantage of the fact that different reference test cases in the reference test case set test different partial code paths of the software code, resulting in different degrees of contribution of different reference test cases to the test coverage rate of the software code, candidate test cases with a contribution degree to the test coverage rate greater than the target contribution degree are screened out from the reference test case set, and then the target code paths tested by the candidate test cases are obtained. With the goal of increasing the correlation between the code paths tested by the test cases in the reference test case set and the target code paths, the reference test case set is adjusted to obtain the target test case set. That is, by screening candidate test cases with a relatively large contribution degree to the test coverage rate and adjusting the reference test cases in the reference test case set according to the target code paths tested by the candidate test cases, effective test cases are automatically detected and identified, and the execution paths of the effective test cases are used to optimize the test cases, improving the effectiveness of the test cases, and overcoming the problem in the related technology that relying on manual writing of test cases and traditional test tools, it is impossible to analyze the triggering conditions of the uncovered code, resulting in difficulty in optimizing the test cases targeted. Therefore, it is possible to solve the technical problems such as low generation efficiency of test cases in the related technology, and achieve the technical effect of improving the generation efficiency of test cases. Description of the Drawings

[0020] To more clearly illustrate the embodiments of this application, the following will briefly introduce the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0021] Figure 1 It is a hardware structure block diagram of a computer device for a method of generating test cases for a software code according to an embodiment of this application;

[0022] Figure 2 It is a flowchart of a method of generating test cases for a software code according to an embodiment of this application;

[0023] Figure 3 It is a flowchart of executing a test task for a method of generating test cases for a software code according to an embodiment of this application;

[0024] Figure 4 It is a structure diagram of a test knowledge base according to an embodiment of this application;

[0025] Figure 5 It is a structure diagram of a test case generation model according to an embodiment of this application;

[0026] Figure 6 It is a flowchart of an uncovered path analysis based on semantic understanding according to an embodiment of this application;

[0027] Figure 7 It is a flowchart for generating test cases by a supplementary test generator according to an embodiment of the present application;

[0028] Figure 8 It is a structural block diagram of a device for generating test cases of software code according to an embodiment of the present application;

[0029] Figure 9 It is a schematic diagram of an electronic device according to an embodiment of the present application. Specific embodiments

[0030] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.

[0031] It should be noted that in the description of the present application, the terms "including", "comprising" or any other variant thereof are intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific order or sequence.

[0032] In order to enable those skilled in the art of the present technology to better understand the solution of the present application, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0033] The method embodiments provided in the embodiments of the present application can be executed on a server device or a similar computing device. Taking running on a server device as an example, Figure 1 It is a hardware structural block diagram of a computer device for a method of generating test cases of software code according to an embodiment of the present application. As Figure 1 shown, the server device may include one or more ( Figure 1 only one is shown in the figure) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Among them, the above-mentioned server device may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic, and it does not limit the structure of the above-mentioned server device. For example, the server device may further include more or fewer components than Figure 1 shown in the figure, or have the same asFigure 1 The different configurations shown.

[0034] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for generating use cases of software code in the embodiments of the present application. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, implements the above-mentioned method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories can be connected to the server device through a network. Examples of the above-mentioned network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and their combinations.

[0035] The transmission device 106 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wireless network provided by a communication provider of the server device. In one instance, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices through a base station and thus can communicate with the Internet. In one instance, the transmission device 106 can be a radio frequency (Radio Frequency, abbreviated as RF) module, which is used to communicate with the Internet wirelessly.

[0036] This application proposes a method for generating test cases for software code. Before describing the optional embodiments of this application, in order to better understand the inventive concept of this application and the creativity of this solution, the related technologies will be described first: Taking the code to be tested as the code of an online food ordering software as an example, when it is necessary to test the integrity and effectiveness of this software code, the common method for generating test cases for software code in the related technologies is as follows: First, the test engineer analyzes the main functional modules included in the code based on the requirement document and code logic of the online food ordering software code, such as core functions like user registration and login, dish browsing and selection, order generation and payment, order status tracking, merchant order receiving and processing, etc. Then, test cases are written for each functional module. Taking the user registration and login function as an example, when the test engineer designs test cases based on their own experience, they may consider test cases for normal situations such as logging in with correct account passwords, and test cases for abnormal scenarios such as entering incorrect passwords and non-existent accounts. For the dish browsing and selection function, the test engineer may design test cases for regular operations such as normal dish browsing and filtering dishes by different categories. After completing the writing of test cases, the test engineer then uses testing tools such as JaCoCo and Istanbul to collect code coverage data when the code executes the test cases, and evaluates the integrity and effectiveness of the online food ordering software code through these data.

[0037] However, the method for generating test cases for software code in the related technologies has the following technical problems:

[0038] 1) The efficiency of manually writing test cases is low and it is easy to miss boundary conditions. For example, when testing the dish browsing and selection function, it is easy to overlook the situation where the dish inventory is displayed as "0", which affects the test quality and cycle, and makes it difficult to discover potential software defects;

[0039] 2) Traditional testing tools can only count code coverage data and cannot analyze the triggering conditions of uncovered code, making it lack data support for test engineers to optimize test cases and making it difficult to improve test cases targeted;

[0040] 3) The applicability of manually designed test cases is poor. When facing changes in business scenarios or code patterns, the original test cases are difficult to be directly used in new scenarios and need to be redesigned and adjusted, which affects the test efficiency.

[0041] To solve the above problems, an embodiment of this application provides a method for generating test cases for software code, Figure 2 which is a flowchart of a method for generating test cases for software code according to an embodiment of this application, as Figure 2 shown. This process includes the following steps:

[0042] Step S12: Detect the test parameters of the software code against the reference test case set. Each reference test case in the reference test case set is used to test a partial code path of the software code, and the test parameter is used to indicate the contribution degree of each reference test case to the test coverage rate of the software code.

[0043] Step S14: Screen out the candidate test cases from the reference test case set whose test parameters meet the parameter conditions. Among them, the contribution degree of the test cases whose test parameters meet the parameter conditions to the test coverage rate is greater than the target contribution degree.

[0044] Step S16: Obtain the target code path tested by the candidate test cases.

[0045] Step S18: Adjust the reference test case set according to the target code path to obtain the target test case set. Among them, the correlation degree between the code paths tested by the target test case set and the target code path is greater than the correlation degree between the code paths tested by the reference test case set and the target code path.

[0046] Optionally, in this embodiment, the software code may be, but is not limited to, the code of software with requirements for test integrity and effectiveness, such as transaction processing system code, medical device control software code, and energy management system code, etc. In this embodiment, the software code is taken as an example of the transaction processing system code, but the type of the software code is not limited. According to the actual test requirements, the software code may also be multiple types of codes.

[0047] Optionally, in this embodiment Figure 3 is a flowchart for executing a test task according to a method for generating test cases for a software code according to an embodiment of the present application. As Figure 3 shown, the process of executing a test task by the method for generating test cases for a software code may include, but is not limited to:

[0048] Step S101: Access the code library to obtain the software code.

[0049] Step S102: Apply semantic analysis to obtain the code semantic understanding result of the software code.

[0050] Step S103: Obtain the code coverage test knowledge base, where a variety of test cases are stored in the test knowledge base.

[0051] Step S104: Obtain the initial test case set. The initial test case set covers the main function paths and common boundary conditions of the software code. According to the code semantic understanding result, retrieve the historical test case templates similar to the current code structure or business domain from the test knowledge base, and perform parametric adjustment to generate the initial test case set. The reference test case set includes the initial test case set.

[0052] Step S105: Execute a test. Execute the initial test cases to obtain the coverage data for this test (i.e., the test coverage).

[0053] Step S106: Analyze the coverage data. Perform an uncovered path analysis based on semantic understanding.

[0054] Step S107: Activate the intelligent feedback mechanism.

[0055] Step S108: Generate supplementary test cases.

[0056] Step S109: Update the knowledge base. Evaluate the effectiveness of the newly generated test cases, convert the effective test strategies into structured knowledge entries and integrate them into the corresponding levels of the knowledge base to update the knowledge base. At the same time, evaluate the effectiveness of the existing knowledge entries and eliminate the invalid ones.

[0057] Step S110: Detect whether the coverage meets the requirements. If it meets the requirements, execute Step S111; otherwise, execute Step S105.

[0058] Step S111: Complete the test and output the final test report and the coverage analysis result (test coverage).

[0059] Optionally, in this embodiment, a code acquisition and analysis module can be used to acquire software code and perform a preliminary parsing on the software code. The code acquisition and analysis module parses the acquired software code through abstract syntax tree technology combined with static code analysis tools, supports code analysis of multiple mainstream programming languages (Java, Python, C++, JavaScript, etc.), and can support new languages through plug-in extensions.

[0060] Optionally, in this embodiment, the code semantic understanding results can include, but are not limited to: the code logic, critical paths, and potential boundary conditions of the software code. The code semantic understanding results can be, but are not limited to, the output results obtained by inputting the software code into a semantic understanding model. The semantic understanding model can be, but is not limited to, a code semantic analysis model based on Transformer. The model is trained by inputting a code sample containing 10 million lines of open-source code, integrating a code-natural language bidirectional mapping model and a code execution flow graph neural network, capable of understanding the relationship between code comments and implementations, and capturing the dynamic execution characteristics of the code, and having the ability to understand code logic, identify critical paths, and potential boundary conditions.

[0061] Optionally, in this embodiment Figure 4 is a structural diagram of a test knowledge base according to an embodiment of the present application, as shown in Figure 4As shown in the figure, the test knowledge base adopts a multi-level architecture design to store various test cases, including: a code syntax layer that stores the syntax rules, API features, and common usage patterns of programming languages; a code semantics layer that stores function call relationships, data flow dependencies, and control flow graphs; a test pattern layer that stores effective test strategies and use case templates corresponding to different code structures; and a domain knowledge layer that stores test experience and best practices in specific business domains. The test knowledge base updates the test cases stored internally through three mechanisms: expert experience coding, automatic learning, and collaborative update, and supports application methods such as similarity retrieval, pattern matching, and knowledge reasoning; its storage layer is designed with a hierarchical storage structure of multi-dimensional cross-indexing that can be implemented based on a graph database, the index layer realizes knowledge retrieval based on semantics and supports fuzzy matching and similarity search, the reasoning layer supports knowledge reasoning and uncertainty processing based on a rule engine and a probabilistic graph model, and the application layer provides call interfaces to support other modules to call knowledge resources. In addition, the knowledge base supports incremental learning, continuously optimizes the quality of knowledge entries through a feedback loop, and implements a knowledge validity evaluation mechanism to regularly eliminate low-value knowledge.

[0062] Optionally, in this embodiment, the reference test case set is a set of test cases that assist in the current software test. These test cases can come from different sources, including but not limited to: test cases from past similar software projects, industry standard test cases, relevant cases in open source test case libraries, and test cases constructed based on the current software code, etc.

[0063] Optionally, in this embodiment, each reference test case in the reference test case set can be used to test a partial code path of the software code. The test coverage rate (i.e., code coverage rate) of the reference test case set for the software code can be obtained by calculating the ratio of the code paths tested by the reference test case set to all the code paths of the software code.

[0064] Optionally, in this embodiment, the steps to obtain the test coverage rate of the reference test case set for the software code include: executing all the reference test cases in the reference test case set; counting the partial execution paths in the software code triggered by each reference test case during execution (i.e., the code paths actually executed by the reference test case during runtime); and obtaining the test coverage rate of the reference test case set for the software code by calculating the ratio of the execution paths in the software code triggered during the execution of all the reference test cases to all the execution paths of the software code.

[0065] Optionally, in this embodiment, the test parameters of the reference test case set for the software code can be detected in the following ways, but are not limited thereto: Analyze the test coverage rate obtained after executing all the reference test cases in the reference test case set, obtain the actual executed code paths of each reference test case during runtime, evaluate the contribution degree of each reference test case to the test coverage rate according to the actual executed code paths corresponding to all the reference test cases, that is, quantify to what extent each reference test case helps improve the code coverage rate, and obtain the test parameters.

[0066] Optionally, in this embodiment, the contribution degree of each reference test case can be obtained by calculating the ratio of the number of executed code paths of the software code triggered by this reference test case to the total number of all executed code paths of the software code.

[0067] Optionally, in this embodiment, the target contribution degree can be a preset fixed value or a dynamic value that is dynamically adjusted according to the current test coverage rate level, and is used to determine whether a test case is sufficiently effective for the code coverage rate. Only when the contribution degree of the test case is greater than this threshold, is this test case considered to be sufficiently effective for the code coverage rate, that is, a test case that can more effectively trigger test scenarios of uncovered paths. Based on the fact that different reference test cases trigger different partial executed code paths in the software code during execution, resulting in different contribution degrees to the test coverage rate, filter out the reference test cases with a contribution degree greater than the target contribution degree from the reference test case set and select them as candidate test cases.

[0068] Optionally, in this embodiment, the target code path is the actual executed code path corresponding to the candidate test case, that is, the path that is considered to make an important contribution to the code coverage rate after screening. Adjust the reference test cases in the reference test case set according to the target code path. By adjusting the reference test case set, make the partial executed code paths of the software code that the test cases in the set can trigger as close as possible to the target code path, and obtain a new target test case set. This means that the contribution degrees of the test cases in the adjusted target test case set to the test coverage rate are all greater than the target contribution degree, and can more effectively trigger test scenarios of uncovered paths.

[0069] This application screens candidate test cases with a relatively large contribution degree to the test coverage rate, and adjusts the reference test cases in the reference test case set according to the target code paths tested by the candidate test cases, realizes automatic detection and identification of effective test cases, and optimizes the test cases using the executed paths of the effective test cases to improve the effectiveness of the test cases, overcoming the problems in the related art that rely on manually writing test cases and traditional test tools, and are unable to analyze the triggering conditions of uncovered code, resulting in difficulties in targeted optimization of test cases. Thus, the technical effect of improving the generation efficiency of test cases is achieved, and further solves technical problems such as low generation efficiency of test cases.

[0070] As an alternative solution, the test parameters of the reference test case set for the software code are detected, including:

[0071] S21, obtaining the path novelty parameter, path complexity parameter, and path weight parameter corresponding to the code path tested by each reference test case in the reference test case set, where the path novelty parameter is used to indicate the novelty degree of the corresponding code path during the testing process of the software code. The lower the frequency of the code path being tested during the testing process of the software code, the higher the novelty degree. The path complexity parameter is used to indicate the complexity of the internal logic of the corresponding code path, and the path weight parameter is used to indicate the importance of the business function carried by the corresponding code path in the entire software code;

[0072] S22, generating test parameters according to the path novelty parameter, path complexity parameter, and path weight parameter of the code path.

[0073] Optionally, in this embodiment, the test parameters of the reference test case set for the software code can be detected but are not limited to according to the following steps: First, obtain the test coverage rate of the reference test case set for the software code, and convert the test coverage rate into a structured form, including the covered path set and the uncovered path set , where each execution path is represented as an ordered node sequence . Obtain the code path actually executed by each reference test case during runtime from the covered path set . For example, the code path actually executed by the i-th reference test case during runtime is the code path in the covered path set . Then, by evaluating the frequency of the code path being tested, the complexity of the internal logic, and the importance of the business function carried in the entire software code during the testing process of the software code, obtain the path novelty parameter , path complexity parameter , and path weight parameter corresponding to the code path , where the higher the path novelty parameter , the lower the frequency of the code path being tested during the testing process of the software code, that is, the higher the novelty degree of the code path. The higher the path complexity parameter , the more complex the internal logic of the code path . The higher the path weight parameter , the more important the business function carried by the code path in the entire software code. Calculate the test parameters according to the path novelty parameter, path complexity parameter, and path weight parameter of the code path.

[0074] Optionally, in this embodiment, after obtaining the path novelty parameter, path complexity parameter, and path weight parameter corresponding to the code path tested by each reference use case in the reference use case set, it is also possible but not limited to generate test parameters according to the following steps: Also obtain the path length parameter and path dependency relationship parameter corresponding to the code path tested by each reference use case in the reference use case set, where the larger the path length parameter, the more logical information is covered, and the path dependency relationship parameter is used to indicate the number of other execution paths or modules that the execution path depends on. The larger the path dependency relationship parameter, the more paths or modules are affected by the execution path. Generate test parameters based on the path novelty parameter, path complexity parameter, path weight parameter, path length parameter, and path dependency relationship parameter of the code path. Through the above parameters related to multiple execution paths, the contribution degree of each reference use case to the test coverage rate can be evaluated more comprehensively, so as to more effectively screen out the test cases with greater contribution to the test coverage rate.

[0075] As an optional solution, generating test parameters based on the path novelty parameter, path complexity parameter, and path weight parameter of the code path includes:

[0076] S31, when the reference use case set includes N reference use cases, and the i-th reference use case among the N reference use cases is used to test the j-th code path in the software code, generate the i-th test parameter of the i-th reference use case through the following steps, where N is an integer greater than 1, i is an integer greater than or equal to 1 and less than or equal to N, and j is an integer greater than or equal to 1:

[0077] S32, obtain the j-th path novelty parameter, j-th path complexity parameter, and j-th path weight parameter corresponding to the j-th code path;

[0078] S33, perform a multiplication operation on the j-th path novelty parameter, j-th path complexity parameter, and j-th path weight parameter to obtain the i-th test parameter.

[0079] Optionally, in this embodiment, assume that the reference use case set includes N reference use cases, and when the i-th reference use case among the N reference use cases actually executes the code path in the software code as the j-th code path it is possible but not limited to generate the i-th test parameter of the i-th reference use case according to the following steps: Obtain the j-th path novelty parameter corresponding to the j-th code path 、the j-th path complexity parameter and the j-th path weight parameter , and obtain the i-th test parameter according to the following formula:

[0080] .

[0081] Among them, is the test parameter of the i-th reference test case, indicating its contribution degree to the test coverage rate.

[0082] As an optional solution, candidate test cases whose test parameters meet the parameter conditions are screened out from the reference test case set, including:

[0083] S41, detecting whether there is a reference test case in the reference test case set whose test parameter is greater than a preset threshold;

[0084] S42, when it is detected that there is a reference test case in the reference test case set whose test parameter is greater than the preset threshold, determining the reference test case whose test parameter is greater than the preset threshold as a candidate test case, where the size of the test parameter is positively correlated with the contribution degree of each reference test case to the test coverage rate of the software code;

[0085] S43, when it is detected that there is no reference test case in the reference test case set whose test parameter is greater than the preset threshold, screening out the reference test case with the largest test parameter from the reference test case set as a candidate test case.

[0086] Optionally, in this embodiment, after executing all the reference test cases in the reference test case set, according to the partial execution paths in the software code triggered by each reference test case during the execution process, the test parameter corresponding to each reference test case can be obtained. Candidate test cases can be screened out from multiple reference test cases through the following steps, but are not limited to: obtaining a preset threshold, comparing the test parameter of each reference test case with the preset threshold, and when there is a reference test case in the reference test case set whose test parameter is greater than the preset threshold, determining the reference test case whose test parameter is greater than the preset threshold as a candidate test case. When there is no reference test case in the reference test case set whose test parameter is greater than the preset threshold, screening out the reference test case with the largest test parameter from the reference test case set as a candidate test case.

[0087] By screening out candidate test cases with a greater contribution to the test coverage rate, the screening efficiency of test cases is improved, unnecessary test cases are reduced, the effectiveness of test cases is ensured, and the test case generation strategy can dynamically adapt to different situations, thereby significantly improving the overall test efficiency and quality.

[0088] As an optional solution, before detecting the test parameters of the reference test case set for the software code, the method includes:

[0089] S51. Input the software code into the use case generation model. The use case generation model includes a code input layer, a semantic understanding layer, a use case generation layer, and a use case output layer. The code input layer is connected to the use case generation layer through the semantic understanding layer, and the use case generation layer is also connected to the use case output layer. The semantic understanding layer is used to extract reference semantic information and reference logic information from the software code input by the code input layer. The reference semantic information is used to indicate the semantics expressed by the software code, and the reference logic information is used to indicate the code logic executed by the software code. The use case generation layer is used to obtain the reference semantic information and reference logic information extracted by the semantic understanding layer, and match one or more reference use cases corresponding to the reference semantic information and reference logic information from the use case database. The use case database records the semantic information, logic information, and use cases with corresponding relationships. The use case output layer is used to output one or more reference use cases matched by the use case generation layer.

[0090] S52. Determine one or more reference use cases output by the use case generation model as a reference use case set.

[0091] Optionally, in this embodiment, Figure 5 is a structural diagram of a use case generation model according to an embodiment of the present application. As Figure 5 shown, the use case generation model includes:

[0092] Code input layer, which can be connected to a software code repository with test requirements, obtain the software code to be tested, and perform preliminary parsing on the obtained software code to extract the code structure, variable type, function call relationship, and conditional branch in the software code.

[0093] Semantic understanding layer, which includes a semantic understanding model and can extract reference semantic information and reference logic information from the code input layer. The reference semantic information includes the semantics expressed by the software code, such as the function of a function, the meaning of a variable, etc. The reference logic information includes the execution logic of the software code, such as conditional branches, loop structures, etc.

[0094] Use case database, which includes a test knowledge base, records the semantic information, logic information, and test cases with corresponding relationships, and adopts a regular knowledge elimination and enhancement mechanism to ensure the efficiency and timeliness of the use cases in the use case database.

[0095] Use case generation layer, which includes a coverage analyzer, an uncovered path analyzer, an intelligent feedback analysis engine, and a supplementary test generator, and is used to match one or more corresponding reference use cases from the use case database according to the reference semantic information and reference logic information extracted by the semantic understanding layer.

[0096] Use case output layer: can output the reference use cases matched by the use case generation layer.

[0097] Optionally, in this embodiment, the use case database may but is not limited to having: utility evaluation, defining knowledge entries Utility function of:

[0098] .

[0099] Among them, each factor represents success rate, coverage gain, and applicable scope respectively; forgetting curve: the weight of low-utility knowledge entries decays over time; knowledge distillation: regularly merge similar knowledge entries and extract common rules; anomaly detection: identify abnormal entries that conflict with mainstream knowledge and conduct manual review.

[0100] Optionally, in this embodiment, the use case generation layer may but is not limited to having: extracting test constraint conditions from code semantics and context; automatically determining test strategies according to code complexity and risk level; generating diverse test input data to cover normal scenarios, boundary conditions, and abnormal situations; constructing complete test scripts, including pre-test preparations, execution steps, and assertion verification.

[0101] Optionally, in this embodiment, the intelligent feedback analysis engine may but is not limited to having: integrating mainstream coverage tools (such as JaCoCo, Istanbul, etc.) and unifying data formats; implementing incremental coverage calculation and contribution evaluation algorithms; dynamically adjusting test generation strategies based on a reinforcement learning framework; using gradient boosting decision trees to predict the coverage gain of specific test strategies.

[0102] Optionally, in this embodiment, the uncovered path analyzer may but is not limited to having: converting code execution paths into multi-dimensional semantic feature vectors; clustering and prioritizing paths based on factors such as business criticality, execution complexity, and error propagation impact; identifying code paths with implicit semantic associations but no direct call relationships; generating a structured uncovered path report by comprehensively considering input construction difficulty, environmental dependence, and trigger condition complexity.

[0103] Optionally, in this embodiment Figure 6 is a flowchart of an uncovered path analysis based on semantic understanding according to an embodiment of the present application. As Figure 6 shown, the trigger condition identification of the uncovered path includes:[[]]

[0104] Step S601, path semantic vectorization. Convert the code execution path into a semantic representation vector and introduce a multi-dimensional semantic feature space , where each dimension represents a specific semantic attribute, such as business function relevance, execution risk, state transition complexity, etc.

[0105] Step S602, semantic clustering analysis. Conduct intelligent clustering on the uncovered paths based on semantic similarity and construct a semantic clustering graph , where: represents the set of uncovered paths; represents the semantic association between paths; represents the association strength weight matrix, which can identify sets of paths with different syntactic structures but similar semantic functions.

[0106] Step S603, critical path priority evaluation. Through the semantic importance function evaluate the business value and technical importance of each uncovered path , and the calculation formula is:

[0107]

[0108] where is a weight coefficient adaptively adjusted according to project characteristics, rather than a fixed value. This function particularly focuses on the factor of State Dependency, which is ignored in traditional coverage analysis, and can effectively identify high-value test paths related to state transitions.

[0109] Step S604, semantic context association analysis. Construct the semantic dependency chain of paths , identify code fragments with implicit semantic associations but no direct call relationships, and discover "jumping" execution paths that cannot be identified by traditional static analysis, which is applicable to complex interaction scenarios in microservice architectures and event-driven systems.

[0110] Step S605, path testability evaluation. Calculate the testability index of the uncovered path , comprehensively considering the input construction difficulty, environmental dependency, and trigger condition complexity, which can more accurately predict the test difficulty and avoid wasting resources on paths that are difficult to test.

[0111] Step S606, based on the above analysis results, generate a structured uncovered path report, including path classification, priority ranking, and test suggestions, providing precise guidance for generating subsequent supplementary test cases.

[0112] Optionally, in this embodiment, Figure 7 is a flowchart for generating test cases by a supplementary test generator according to an embodiment of the present application, as shown in Figure 7As shown, the steps for the supplementary test generator to generate test cases can include but are not limited to: First, perform semantically guided test scenario construction. Input the uncovered path analysis report, which includes path semantic features and priorities. Map the path semantic features to a predefined test scenario template library and output an abstract scenario description, which includes the key operation sequence required to trigger the target path. Next, perform reverse derivation of path activation conditions. Extract all branch condition expressions from the target path and use a hybrid symbolic execution technique to solve the range of input values that satisfy the conditions, paying special attention to boundary values and special values such as zero values, maximum / minimum values, overflow values, etc., and use an improved combinatorial testing algorithm to generate an efficient conditional combination test set. Then, perform intelligent processing of data dependencies. Construct a dependency relationship graph between test data items through static and dynamic analysis, propagate constraint conditions based on the dependency relationship graph to ensure data consistency, design a priority-based conflict resolution strategy to handle data constraint conflicts, and generate specific test data that meets the requirements based on the constraint conditions. After that, perform context-aware test sequence generation. Construct a system state transition model based on code analysis, map the target path to state transition requirements, design an optimal operation sequence that can trigger the required state transition chain, and verify the effectiveness of the sequence through lightweight simulation. Next, perform intelligent configuration of environment simulation. Identify the environmental conditions on which path execution depends, automatically generate environment configuration scripts, including resource configuration, network settings, etc., design a specific exception triggering mechanism for exception handling paths, and automatically design a thread scheduling strategy for concurrency-related paths. Then, there is an incremental optimization mechanism. Evaluate the coverage gain after generating a batch of test cases, dynamically adjust the generation parameters based on the gain data, and maintain a test strategy effect database to support experience accumulation. Finally, perform test case generation. Convert the generated test cases into the format of a specified test framework, add annotations and structured information to improve maintainability, and generate a batch execution script to support automated testing. Through these steps, the supplementary test generator can generate high-quality test cases, effectively improving test coverage and test efficiency.

[0113] Optionally, in this embodiment, taking the online payment system code as an example, the reference use case set can be obtained from the use case generation model through the following steps: input the online payment system code into the code input layer; analyze the code through the semantic understanding layer to extract the reference semantic information (such as user login function, payment processing function, and refund processing function) and reference logical information (such as conditional branches including payment success and payment failure; loop structures including multiple payment attempts; exception handling including network exceptions and fund freezing) in the code; the use case generation layer matches the corresponding reference use cases from the use case database according to the extracted information, such as: Use Case 1 - Test user login function, Use Case 2 - Test normal payment success path, Use Case 3 - Test payment failure handling path, Use Case 4 - Test refund processing path under the fund freezing state, and Use Case 5 - Test payment processing path under specific network exceptions; the use case output layer outputs the matched reference use cases 1-5 to obtain the reference use case set.

[0114] Through the use case generation model, semantic and logical information can be automatically extracted from the software code to be tested, and the corresponding test cases can be generated, thus significantly reducing the workload of manually writing test cases. With the help of the semantic understanding layer and the use case generation layer, the generated test cases can more accurately cover the key functions and logical paths of the software code, ensuring the comprehensiveness and effectiveness of the test. In addition, the use case generation model has dynamic adaptability and can generate new test cases in a timely manner according to the changes in the software code, ensuring the timeliness and effectiveness of the test cases. Finally, the automatically generated test case set can be directly applied to subsequent test parameter detection and screening, further improving the overall efficiency of the test.

[0115] As an optional solution, adjust the reference use case set according to the target code path to obtain the target use case set, including:

[0116] S61, obtain the path weight parameter of each code path in the software code from the model parameters of the use case generation model, where the path weight parameter is used to indicate the degree of association between the use cases generated by the use case generation model and the corresponding code paths, and the greater the path weight parameter, the higher the degree of association between the use cases generated by the use case generation model and the corresponding code paths;

[0117] S62, increase the target path weight parameter corresponding to the target code path to obtain an adjusted target use case generation model;

[0118] S63, input the software code into the target use case generation model to obtain the target use case set output by the target use case generation model.

[0119] Optionally, in this embodiment, the target use case set may, but is not limited to, be a test case set that meets the test objectives after adjusting the reference use case set. The use cases in the target use case set cover the execution paths of the software code more comprehensively and effectively.

[0120] Optionally, in this embodiment, the target use case set may be obtained through the following steps, but is not limited thereto: First, obtain the path weight parameters of each code path in the software code from the model parameters of the use case generation model. For example, the weight parameter of the normal order placement path is 0.8, the weight parameter of the out-of-stock handling path is 0.7, the weight parameter of the payment failure retry path is 0.6, and the weight parameter of the network interruption handling path is 0.5 (this is an uncovered path). Then, according to the priority feedback strategy, it is found that the network interruption handling path is an important uncovered path. Therefore, an operation to increase its weight parameter is taken, and the weight parameter of the network interruption handling path is increased from 0.5 to 0.9 to improve the attention of the use case generation model to this path. Finally, input the software code into the adjusted target use case generation model to generate a new target use case set. Since the weight parameter of the network interruption handling path is increased, the model will generate more test cases for this path.

[0121] Optionally, in this embodiment, by analyzing the covered path set and the uncovered path set, adjust the path weight parameters corresponding to each code path in the software code in the model parameters of the use case generation model, so as to increase the association degree between the use cases generated by the use case generation model and the corresponding code paths. Make the test cases generated by adjusting the use case generation model more focused on testing important code paths.

[0122] As an optional solution, after inputting the software code into the target use case generation model to obtain the target use case set output by the target use case generation model, the method further includes:

[0123] S71, extract the new use cases that are different between the target use case set and the reference use case set;

[0124] S72, obtain the new semantic information and new logical information corresponding to the new use cases;

[0125] S73, add the corresponding new semantic information, new logical information, and new use cases to the use case database.

[0126] Optionally, in this embodiment, the use cases in the use case database may be updated through the following steps, but are not limited thereto: Based on the target use case set generated by the target use case generation model, by calculating the covered path set corresponding to the target use case set and the covered path set corresponding to the reference use case set the difference between them to obtain the newly added test cases with differences between the target test case set and the reference test case set; for each newly added test case, obtain the semantic information and logical information of the code paths covered by each newly added test case; convert the newly added test cases and their corresponding semantic and logical information into structured knowledge entries and add them to the test case database (including the test knowledge base) for subsequent reuse.

[0127] By obtaining the target code paths, accurately locate the key points of testing to ensure that testing resources are concentrated on the critical code paths. By adjusting the reference test case set according to the target code paths to generate a new target test case set, it can dynamically adapt to code changes and complex logics, ensuring the timeliness and effectiveness of the test cases. Adding test cases for uncovered paths significantly improves the code coverage.

[0128] Path similarity evaluation: Adopt a variant of the edit distance to calculate the similarity between path sets and identify paths with similar structures but different semantics. For example, there are two paths, one is the payment path in a normal network environment, and the other is the payment path in a weak network environment. Through path similarity evaluation, it can be found that they have similar structures but different semantics, so as to more accurately evaluate the impact of different network environments on the payment path coverage rate.

[0129] Optionally, in this embodiment, in order to better understand the process of executing the test task for the method of generating test cases for the above software code, the following further describes the process of executing the test task for the method of generating test cases for the above software code in combination with optional embodiments, but it is not used to limit the technical solutions of the embodiments of the present application.

[0130] In this embodiment, a method for generating test cases for software code is provided, which mainly includes the following steps:

[0131] Step 1, access the code to be tested and configuration parameters. The system is integrated with code repositories (such as Git, SVN) and CI / CD pipelines (such as Jenkins, GitHub Actions); configure test strategy parameters such as target coverage rate, priority rules, and resource limitations; import domain knowledge and historical test data to initialize the knowledge base; select appropriate semantic understanding models and test generation strategies according to the characteristics of the software code.

[0132] Step 2, incremental testing and continuous optimization, perform intelligent testing on the changed part of the code. Compare the differences between code versions to identify the affected code areas; based on the dependency graph analysis, determine the scope of influence of the changes; allocate more testing resources to high-risk areas; ensure that the existing functions are not affected by the new changes.

[0133] Step 3. To improve the testing efficiency of large-scale projects, the system supports a distributed architecture. The master node is responsible for task scheduling, policy optimization, and result aggregation; the worker nodes execute test case generation and execution in parallel; the shared knowledge base enables cross-node knowledge synchronization; the elastic scaling architecture supports on-demand adjustment of computing resources.

[0134] Through the description of the above implementation manners, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation manner.

[0135] Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application.

[0136] In this embodiment, a device for generating use cases of software code is also provided. The device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that can implement a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.

[0137] Figure 8 is a structural block diagram of a device for generating use cases of software code according to an embodiment of the present application; as Figure 8 shown, it includes:

[0138] A detection module 802, configured to detect test parameters of software code for a set of reference use cases, where each reference use case in the set of reference use cases is used to test a partial code path of the software code, and the test parameters are used to indicate the contribution degree of each reference use case to the test coverage rate of the software code;

[0139] A screening module 804, configured to screen out candidate use cases whose test parameters meet the parameter conditions from the set of reference use cases, where the use cases whose test parameters meet the parameter conditions have a contribution degree to the test coverage rate greater than the target contribution degree;

[0140] A first obtaining module 806, configured to obtain the target code path tested by the candidate use cases;

[0141] An adjustment module 808, configured to adjust a set of reference test cases according to a target code path to obtain a set of target test cases, where the relevance between the code paths tested by the set of target test cases and the target code path is greater than the relevance between the code paths tested by the set of reference test cases and the target code path.

[0142] In an exemplary embodiment, the detection module includes:

[0143] A first acquisition unit, configured to acquire a path novelty parameter, a path complexity parameter, and a path weight parameter corresponding to the code path tested by each reference test case in the set of reference test cases, where the path novelty parameter is used to indicate the novelty degree of the corresponding code path during the testing process of the software code, and the lower the frequency of the code path being tested during the testing process of the software code, the higher the novelty degree, the path complexity parameter is used to indicate the complexity degree of the internal logic of the corresponding code path, and the path weight parameter is used to indicate the importance degree of the service function carried by the corresponding code path in the entire software code;

[0144] A generation unit, configured to generate test parameters according to the path novelty parameter, the path complexity parameter, and the path weight parameter of the code path.

[0145] In an exemplary embodiment, the generation unit is further configured to:

[0146] When the set of reference test cases includes N reference test cases, and the i-th reference test case in the N reference test cases is used to test the j-th code path in the software code, generate the i-th test parameter of the i-th reference test case through the following steps, where N is an integer greater than 1, i is an integer greater than or equal to 1 and less than or equal to N, and j is an integer greater than or equal to 1:

[0147] Acquire the j-th path novelty parameter, the j-th path complexity parameter, and the j-th path weight parameter corresponding to the j-th code path;

[0148] Perform a multiplication operation on the j-th path novelty parameter, the j-th path complexity parameter, and the j-th path weight parameter to obtain the i-th test parameter.

[0149] In an exemplary embodiment, the screening module includes:

[0150] A detection unit, configured to detect whether there is a reference test case in the set of reference test cases whose test parameter is greater than a preset threshold;

[0151] A determination unit, configured to, when detecting that there is a reference test case in the set of reference test cases whose test parameter is greater than the preset threshold, determine the reference test case whose test parameter is greater than the preset threshold as a candidate test case, where the size of the test parameter is positively correlated with the contribution degree of each reference test case to the test coverage rate of the software code;

[0152] A screening unit, configured to screen out the reference use case with the largest test parameter from the reference use case set as a candidate use case when it is detected that there is no reference use case in the reference use case set whose test parameter is greater than a preset threshold.

[0153] In an exemplary embodiment, the apparatus further includes:

[0154] An input module, configured to input the software code into a use case generation model before detecting the test parameter of the reference use case set for the software code. The use case generation model includes a code input layer, a semantic understanding layer, a use case generation layer, and a use case output layer. The code input layer is connected to the use case generation layer through the semantic understanding layer, and the use case generation layer is further connected to the use case output layer. The semantic understanding layer is configured to extract reference semantic information and reference logic information from the software code input by the code input layer. The reference semantic information is used to indicate the semantics expressed by the software code, and the reference logic information is used to indicate the code logic executed by the software code. The use case generation layer is configured to obtain the reference semantic information and reference logic information extracted by the semantic understanding layer, and match one or more reference use cases corresponding to the reference semantic information and reference logic information from a use case database. The use case database records semantic information, logic information, and use cases with corresponding relationships. The use case output layer is configured to output one or more reference use cases matched by the use case generation layer;

[0155] An output module, configured to determine one or more reference use cases output by the use case generation model as the reference use case set.

[0156] In an exemplary embodiment, the adjustment module includes:

[0157] A second acquisition unit, configured to acquire the path weight parameter of each code path in the software code from the model parameters of the use case generation model, where the path weight parameter is used to indicate the association degree between the use case generated by the use case generation model and the corresponding code path. The greater the path weight parameter, the higher the association degree between the use case generated by the use case generation model and the corresponding code path;

[0158] An increasing unit, configured to increase the target path weight parameter corresponding to the target code path to obtain an adjusted target use case generation model;

[0159] An input unit, configured to input the software code into the target use case generation model to obtain a target use case set output by the target use case generation model.

[0160] In an exemplary embodiment, the apparatus further includes:

[0161] An extraction module, configured to extract newly added use cases that are different between the target use case set and the reference use case set after inputting software code into a target use case generation model to obtain the target use case set output by the target use case generation model;

[0162] A second acquisition module, configured to acquire newly added semantic information and newly added logical information corresponding to the newly added use cases;

[0163] An addition module, configured to add the newly added semantic information, the newly added logical information, and the newly added use cases with corresponding relationships to a use case database.

[0164] It should be noted that the above-mentioned modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to this: the above-mentioned modules are all located in the same processor; or, the above-mentioned modules are respectively located in different processors in any combination form.

[0165] For the description of the features in the corresponding embodiments of the generation device for use cases of software code, reference can be made to the relevant descriptions in the corresponding embodiments of the generation method for use cases of software code, which will not be elaborated here one by one.

[0166] An embodiment of the present application further provides an electronic device, Figure 9 is a schematic diagram of an electronic device according to an embodiment of the present application, as Figure 9 shown, the electronic device includes a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above-mentioned embodiments of the generation method for use cases of software code.

[0167] In an exemplary embodiment, the above-mentioned electronic device may further include a transmission device and an input / output device. Among them, the transmission device is connected to the above-mentioned processor, and the input / output device is connected to the above-mentioned processor.

[0168] Specific examples in this embodiment may refer to the examples described in the above-mentioned embodiments and exemplary embodiments, and will not be elaborated here.

[0169] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. Among them, the computer program is configured to execute the steps in any one of the above-mentioned embodiments of the generation method for use cases of software code when running.

[0170] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM for short), random access memory (RAM for short), mobile hard disks, magnetic disks, or optical discs.

[0171] An embodiment of the present application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the methods in various embodiments of the present application; the computer program product further includes a non-volatile computer-readable storage medium that stores the computer program, and the computer program, when executed by the processor, implements the steps of the method for generating use cases of the software code in various embodiments of the present application.

[0172] Those skilled in the art can further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0173] The above has introduced in detail a method for generating use cases of software code provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A method for generating test cases of software code, characterized in that, including: detecting test parameters of a reference test case set for software code, wherein each reference test case in the reference test case set is used to test a partial code path of the software code, and the test parameters are used to indicate the contribution degree of each reference test case to the test coverage rate of the software code; screening out candidate test cases whose test parameters meet parameter conditions from the reference test case set, wherein the contribution degree of the test cases whose test parameters meet the parameter conditions to the test coverage rate is greater than the target contribution degree; obtaining a target code path tested by the candidate test cases; adjusting the reference test case set according to the target code path to obtain a target test case set, wherein the correlation degree between the code paths tested by the target test case set and the target code path is greater than the correlation degree between the code paths tested by the reference test case set and the target code path.

2. The method according to claim 1, characterized in that the detecting test parameters of the reference test case set for the software code includes: obtaining a path novelty parameter, a path complexity parameter, and a path weight parameter corresponding to the code path tested by each reference test case in the reference test case set, wherein the path novelty parameter is used to indicate the novelty degree of the corresponding code path during the test process of the software code, and the lower the frequency of the code path being tested during the test process of the software code, the higher the novelty degree, the path complexity parameter is used to indicate the complexity degree of the internal logic of the corresponding code path, and the path weight parameter is used to indicate the importance degree of the service function carried by the corresponding code path in the entire software code; generating the test parameters according to the path novelty parameter, the path complexity parameter, and the path weight parameter of the code path.

3. The method according to claim 2, characterized in that the generating the test parameters according to the path novelty parameter, the path complexity parameter, and the path weight parameter of the code path includes: when the reference test case set includes N reference test cases, and the i-th reference test case among the N reference test cases is used to test the j-th code path in the software code, generating the i-th test parameter of the i-th reference test case through the following steps, where N is an integer greater than 1, i is an integer greater than or equal to 1 and less than or equal to N, and j is an integer greater than or equal to 1: obtaining the j-th path novelty parameter, the j-th path complexity parameter, and the j-th path weight parameter corresponding to the j-th code path; performing a multiplication operation on the j-th path novelty parameter, the j-th path complexity parameter, and the j-th path weight parameter to obtain the i-th test parameter.

4. The method according to claim 1, characterized in that the screening out candidate test cases whose test parameters meet parameter conditions from the reference test case set includes: detecting whether there is a reference test case in the reference test case set whose test parameter is greater than a preset threshold; When it is detected that there is a reference use case in the reference use case set where the test parameter is greater than the preset threshold, determine the reference use case with the test parameter greater than the preset threshold as the candidate use case, where the magnitude of the test parameter is positively correlated with the contribution degree of each reference use case to the test coverage rate of the software code; When it is detected that there is no reference use case in the reference use case set where the test parameter is greater than the preset threshold, screen out the reference use case with the largest test parameter from the reference use case set as the candidate use case.

5. The method according to claim 1, wherein: Before detecting the test parameter of the reference use case set for the software code, the method includes: Input the software code into a use case generation model, where the use case generation model includes a code input layer, a semantic understanding layer, a use case generation layer, and a use case output layer. The code input layer is connected to the use case generation layer through the semantic understanding layer, and the use case generation layer is also connected to the use case output layer. The semantic understanding layer is used to extract reference semantic information and reference logic information from the software code input by the code input layer. The reference semantic information is used to indicate the semantics expressed by the software code, and the reference logic information is used to indicate the code logic executed by the software code. The use case generation layer is used to obtain the reference semantic information and the reference logic information extracted by the semantic understanding layer, and match one or more reference use cases corresponding to the reference semantic information and the reference logic information from a use case database. The use case database records semantic information, logic information, and use cases with corresponding relationships, and the use case output layer is used to output one or more reference use cases matched by the use case generation layer; Determine one or more reference use cases output by the use case generation model as the reference use case set.

6. The method according to claim 5, wherein: Adjusting the reference use case set according to the target code path to obtain a target use case set includes: Obtain the path weight parameter of each code path in the software code from the model parameters of the use case generation model, where the path weight parameter is used to indicate the association degree between the use case generated by the use case generation model and the corresponding code path. The greater the path weight parameter, the higher the association degree between the use case generated by the use case generation model and the corresponding code path; Increase the target path weight parameter corresponding to the target code path to obtain an adjusted target use case generation model; Input the software code into the target use case generation model to obtain the target use case set output by the target use case generation model.

7. The method according to claim 6, wherein: After inputting the software code into the target use case generation model to obtain the target use case set output by the target use case generation model, the method further includes: Extract the new test cases that are different between the target test case set and the reference test case set; Obtain the new semantic information and new logical information corresponding to the new test cases; Add the new semantic information, the new logical information, and the new test cases with corresponding relationships to the test case database.

8. A device for generating test cases of software code, characterized in that it includes: A detection module, configured to detect the test parameters of the software code for the reference test case set, wherein each reference test case in the reference test case set is used to test a partial code path of the software code, and the test parameters are used to indicate the contribution degree of each reference test case to the test coverage rate of the software code; A screening module, configured to screen out candidate test cases whose test parameters meet the parameter conditions from the reference test case set, wherein the contribution degree of the test cases whose test parameters meet the parameter conditions to the test coverage rate is greater than the target contribution degree; A first acquisition module, configured to acquire the target code path tested by the candidate test cases; An adjustment module, configured to adjust the reference test case set according to the target code path to obtain a target test case set, wherein the correlation degree between the code path tested by the target test case set and the target code path is greater than the correlation degree between the code path tested by the reference test case set and the target code path.

9. An electronic device, characterized in that, It includes: A memory, configured to store a computer program; A processor, configured to implement the steps of the method for generating test cases of software code according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the method for generating test cases of software code according to any one of claims 1 to 7 when executed by a processor.

Citation Information

Patent Citations

  • Test case generation method and device, computer equipment and storage medium

    CN112559364A

  • Test case coverage rate evaluation method and device, computer equipment and storage medium

    CN116881117A

  • Test case completion method and system and electronic equipment

    CN118916274A

  • Test case generation device and test case generation method

    JP2015204065A

  • Test case generation for uncovered code paths

    US20180039568A1

Cited By

  • Test case management method, electronic equipment and medium

    CN120780611A

  • A method for managing test cases, electronic devices, and media

    CN120780611B