Test case generation method and device, electronic equipment and storage medium
By constructing a similarity matrix and using clustering algorithms to generate test cases, the problem of incomplete regression testing caused by reliance on manual screening in existing technologies is solved, and more efficient test case generation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CLOUD TECH CO LTD
- Filing Date
- 2022-07-22
- Publication Date
- 2026-07-21
AI Technical Summary
In software development, existing technologies rely on testers' familiarity and personal abilities to select test cases, resulting in incomplete and inefficient regression testing.
By obtaining the target execution parameters of the test cases of the program to be tested, a similarity matrix is constructed. Test cases are generated by combining clustering algorithms and supervised information, including affine propagation clustering and semi-supervised clustering. The similarity matrix is then adjusted to generate more comprehensive test cases.
It improves the efficiency and comprehensiveness of test case generation, reduces the cost of manually screening test cases, and shortens the testing cycle.
Smart Images

Figure CN115168220B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and in particular to a test case generation method, apparatus, electronic device, and storage medium. Background Technology
[0002] In software development, regression testing is required when a service changes or when its upstream or downstream services change. For example, in a microservice architecture, the complex call relationships between services mean that when a core service changes, regression testing of its upstream and downstream services is often necessary.
[0003] Currently, when performing regression testing on services, testers need to select test cases from multiple test cases. This is highly dependent on the testers' familiarity with the business and their personal test case selection ability, which can easily lead to incomplete test cases and low efficiency. Summary of the Invention
[0004] This application provides a test case generation method, apparatus, electronic device, and storage medium for more comprehensive screening of test cases and improving the efficiency of test case generation.
[0005] In a first aspect, embodiments of this application provide a test case generation method, the method comprising:
[0006] Obtain the target execution parameters for each of the multiple test cases in the program under test, wherein the target execution parameters are obtained by executing the corresponding test cases during the operation of the program under test;
[0007] Determine the similarity of the target execution parameters between any two use cases from the plurality of use cases, and obtain a similarity matrix;
[0008] The multiple use cases are clustered based on the similarity matrix to obtain an initial clustering result, which includes at least one set of use cases.
[0009] The following operations are performed using an iterative update method until the first iteration termination condition is met: the similarity matrix is adjusted based on the supervision information and the clustering results, and the multiple use cases are clustered based on the adjusted similarity matrix to obtain the current clustering results; wherein, the supervision information includes the association relationships between the use cases in the multiple use cases;
[0010] Select the set of test cases that meet the first preset condition from the latest clustering results and generate test cases.
[0011] In one possible embodiment, the step of clustering the multiple use cases based on the similarity matrix to obtain initial clustering results includes:
[0012] For any two use cases among the plurality of use cases, the initial clustering parameters between the two use cases are determined based on the similarity matrix;
[0013] For any two of the multiple use cases, perform the following operations in an iterative update manner until the second iteration termination condition is met: Based on the adjustment parameters and the clustering parameters between the two use cases, obtain the updated clustering parameters between the two use cases;
[0014] The initial clustering results are obtained based on the clustering parameters between each pair of newly obtained use cases.
[0015] In one possible embodiment, the association between the multiple use cases in the supervision information includes: pair constraint information initially set for the program under test and a pre-set use case knowledge base; wherein, the pair constraint information includes at least multiple pairs of positively correlated use cases, and the use case knowledge base includes positive association relationships between use cases and negative association relationships between use cases;
[0016] The adjustment of the similarity matrix based on supervised information and the clustering results includes:
[0017] Repeat the following operations until the first termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select positive use case pairs with positive associations from the plurality of use cases and update them in the pairwise constraint information;
[0018] Repeat the following operations until the second termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select negative use case pairs with negative associations from the plurality of use cases and update them in the pairwise constraint information;
[0019] For any two use cases among the plurality of use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then the similarity of the two use cases is updated to a first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then the similarity of the two use cases in the similarity matrix is updated to a second preset value.
[0020] In one possible embodiment, selecting positive use case pairs with positive correlation from the plurality of use cases based on the pairwise constraint information, the use case knowledge base, and the clustering results includes:
[0021] Based on the pairwise constraint information and the clustering results, two use cases that satisfy the second preset condition are selected from the plurality of use cases;
[0022] If the two use cases are determined to have a positive association based on the use case knowledge base, then the two use cases are considered as a positive use case pair.
[0023] Based on the pairwise constraint information, the use case knowledge base, and the clustering results, negative use case pairs with negative associations are selected from the plurality of use cases, including:
[0024] Based on the pairwise constraint information and the clustering results, two use cases that satisfy the third preset condition are selected from the plurality of use cases;
[0025] If the two use cases are determined to have a negative association based on the use case knowledge base, then the two use cases are treated as a negative use case pair and updated in the pair constraint information.
[0026] In one possible embodiment, selecting two use cases that satisfy the second preset condition from the plurality of use cases based on the pairwise constraint information and the clustering result includes:
[0027] For any two use cases among the plurality of use cases, if the two use cases belong to different use case sets in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the second preset condition.
[0028] The step of selecting two use cases that satisfy the third preset condition from the plurality of use cases based on the pairwise constraint information and the clustering results includes:
[0029] For any two use cases among the plurality of use cases, if the two use cases belong to the same use case set in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the third preset condition.
[0030] In one possible embodiment, selecting the set of use cases that satisfy the first preset condition from the latest clustering results includes:
[0031] From the latest clustering results, select a set of use cases that includes any one of the positive use case pairs from the initial settings; and / or
[0032] From the latest clustering results, select the set of test cases where the target execution parameters of the cluster centers reach the set parameter values.
[0033] In one possible embodiment, the target execution parameters for each use case include: execution association parameters between the use case and the modified program corresponding to the program under test;
[0034] The execution-related parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage.
[0035] Secondly, this application provides a test case generation apparatus, the apparatus comprising:
[0036] The parameter acquisition module is used to acquire the target execution parameters of each of the multiple test cases in the program under test. The target execution parameters are obtained by executing the corresponding test cases during the operation of the program under test.
[0037] The similarity determination module is used to determine the similarity of target execution parameters between any two use cases among the plurality of use cases, and obtain a similarity matrix;
[0038] A clustering module is used to cluster the multiple use cases based on the similarity matrix to obtain an initial clustering result, wherein the clustering result includes at least one set of use cases;
[0039] The supervision module is used to perform the following operations in an iterative update manner until the first iteration termination condition is met: adjusting the similarity matrix based on the supervision information and the clustering results, and performing clustering processing on the multiple use cases based on the adjusted similarity matrix to obtain the current clustering result; wherein, the supervision information includes the association relationship between the use cases in the multiple use cases;
[0040] The generation module is used to select a set of test cases that meet the first preset condition from the latest clustering results and generate test cases.
[0041] In one possible embodiment, the clustering module is further configured to:
[0042] For any two use cases among the plurality of use cases, the initial clustering parameters between the two use cases are determined based on the similarity matrix;
[0043] For any two of the multiple use cases, perform the following operations in an iterative update manner until the second iteration termination condition is met: Based on the adjustment parameters and the clustering parameters between the two use cases, obtain the updated clustering parameters between the two use cases;
[0044] The initial clustering results are obtained based on the clustering parameters between each pair of newly obtained use cases.
[0045] In one possible embodiment, the association between the multiple use cases in the supervision information includes: pair constraint information initially set for the program under test and a pre-set use case knowledge base; wherein, the pair constraint information includes at least multiple pairs of positively correlated use cases, and the use case knowledge base includes positive association relationships between use cases and negative association relationships between use cases;
[0046] When adjusting the similarity matrix based on the supervision information and the clustering results, the supervision module is further configured to:
[0047] Repeat the following operations until the first termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select positive use case pairs with positive associations from the plurality of use cases and update them in the pairwise constraint information;
[0048] Repeat the following operations until the second termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select negative use case pairs with negative associations from the plurality of use cases and update them in the pairwise constraint information;
[0049] For any two use cases among the plurality of use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then the similarity of the two use cases is updated to a first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then the similarity of the two use cases in the similarity matrix is updated to a second preset value.
[0050] In one possible embodiment, when selecting positive use case pairs with positive correlation from the plurality of use cases based on the pairwise constraint information, the use case knowledge base, and the clustering results, the supervision module is further configured to:
[0051] Based on the pairwise constraint information and the clustering results, two use cases that satisfy the second preset condition are selected from the plurality of use cases;
[0052] If the two use cases are determined to have a positive association based on the use case knowledge base, then the two use cases are considered as a positive use case pair.
[0053] When selecting negative use case pairs with negative associations from the plurality of use cases based on the pairwise constraint information, the use case knowledge base, and the clustering results, the supervision module is further configured to:
[0054] Based on the pairwise constraint information and the clustering results, two use cases that satisfy the third preset condition are selected from the plurality of use cases;
[0055] If the two use cases are determined to have a negative association based on the use case knowledge base, then the two use cases are treated as a negative use case pair and updated in the pair constraint information.
[0056] In one possible embodiment, when selecting two use cases that satisfy the second preset condition from the plurality of use cases based on the pairwise constraint information and the clustering result, the supervision module is further configured to:
[0057] For any two use cases among the plurality of use cases, if the two use cases belong to different use case sets in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the second preset condition.
[0058] When selecting two use cases that satisfy the third preset condition from the plurality of use cases based on the pairwise constraint information and the clustering results, the supervision module is further configured to:
[0059] For any two use cases among the plurality of use cases, if the two use cases belong to the same use case set in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the third preset condition.
[0060] In one possible embodiment, the generation module is further configured to:
[0061] From the latest clustering results, select a set of use cases that includes any one of the positive use case pairs from the initial settings; and / or
[0062] From the latest clustering results, select the set of test cases where the target execution parameters of the cluster centers reach the set parameter values.
[0063] In one possible embodiment, the target execution parameters for each use case include: execution association parameters between the use case and the modified program corresponding to the program under test;
[0064] The execution-related parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage.
[0065] Thirdly, this application provides an electronic device, comprising:
[0066] Memory, used to store program instructions;
[0067] A processor is configured to invoke program instructions stored in the memory and execute the steps of the method described in any one of the first aspects according to the obtained program instructions.
[0068] Fourthly, this application provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the method described in any one of the first aspects.
[0069] Fifthly, this application provides a computer program product comprising: computer program code, which, when run on a computer, causes the computer to perform the method described in any one of the first aspects.
[0070] The test case generation method provided in this application has at least the following beneficial effects:
[0071] In this embodiment, the target execution parameters of each of the multiple test cases in the program to be tested are obtained, and the similarity of the target execution parameters between any two test cases is determined to obtain a similarity matrix. Based on this similarity matrix, the multiple test cases are clustered, and the clustering process is guided by supervised information, which includes the relationships between the test cases. Finally, test cases are generated based on the clustering results. This approach saves the cost of manual test case selection, shortens the testing cycle, combines testing experience with clustering algorithms to improve clustering effectiveness, resulting in more comprehensive test cases and increased efficiency in test case generation.
[0072] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0073] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0074] Figure 1 A flowchart illustrating a test case generation method provided in this application embodiment;
[0075] Figure 2 A flowchart illustrating an affine propagation clustering method provided in this application embodiment;
[0076] Figure 3 A flowchart illustrating another test case generation method provided in this application embodiment;
[0077] Figure 4 A structural diagram of a test case generation device provided in an embodiment of this application;
[0078] Figure 5 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0079] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0080] The terms "first" and "second" in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising" and any variations thereof are intended to cover non-exclusive protection. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. The term "multiple" in this application can mean at least two, for example, two, three, or more, and the embodiments of this application do not impose limitations.
[0081] Before introducing the test case generation method provided in the embodiments of this application, for ease of understanding, the technical background of the embodiments of this application will be described in detail below.
[0082] Regression testing primarily verifies that all defects from previous versions have been fixed and confirms that fixing these defects has not led to new defects. Currently, when performing regression testing on a service, testers need to select test cases from multiple options. This heavily relies on the testers' familiarity with the business logic and their individual test case selection skills, which can easily lead to incomplete selection of test cases and low efficiency.
[0083] In view of this, embodiments of this application provide a test case generation method, apparatus, electronic device, and storage medium that can automatically generate test cases. This not only saves the cost of manual test case screening and shortens the testing cycle, but also combines testing experience with clustering algorithms to improve the clustering effect, making the screened test cases more comprehensive and improving the efficiency of test case generation.
[0084] The test case generation method of this application embodiment will be described below with reference to the accompanying drawings and specific embodiments.
[0085] Reference Figure 1As shown in the embodiment of this application, a test case generation method can be executed by a terminal device or a server, and specifically includes the following steps S101-S105:
[0086] Step S101: Obtain the target execution parameters for each of the multiple test cases in the program under test. The target execution parameters are obtained by executing the corresponding test cases during the operation of the program under test.
[0087] When regression testing is required for a service, instrumentation is performed on the service's source code to obtain the program to be tested. Instrumentation involves inserting probes into the source code and then obtaining control flow and data flow information of the source code sequence through the execution of the probes, thereby achieving the testing objective. Furthermore, source code instrumentation is performed based on a complete lexical and syntactic analysis of the source file, which ensures that the instrumentation of the source file can achieve a high degree of accuracy and specificity.
[0088] The test cases for the program under test are full test cases, which include test points for the functionalities used by the program under test. Typically, full test cases are executed periodically for the program under test to obtain the target execution parameters for each test case. When regression testing of the program under test is required, the pre-obtained target execution parameters for each test case can be retrieved.
[0089] When performing regression testing on a program under test, on the one hand, the program under test has undergone program changes; on the other hand, the program under test has not undergone program changes, but the programs of its upstream and downstream services have undergone changes.
[0090] In one possible embodiment, when the program under test undergoes a program change, the target execution parameters for each use case include: execution association parameters between the use case and the changed program corresponding to the program under test; wherein, the execution association parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage.
[0091] Step S102: Determine the similarity of the target execution parameters between any two use cases from multiple use cases, and obtain a similarity matrix.
[0092] Among them, existing similarity measurement methods can be used to determine the similarity of target execution parameters between any two use cases. For example, the negative squared Euclidean distance can be used for measurement, as shown in the following equation (1):
[0093] s(i,j)=-‖x i -x j || 2 (1)
[0094] Where s(i,j) represents the target execution parameter x of test case i. iand the target execution parameter x of use case j j The similarity between two test cases can be expressed as follows: if there are N test cases, the similarity of the target execution parameters between any two test cases can form an N×N similarity matrix R.
[0095] Step S103: Cluster multiple use cases based on the similarity matrix to obtain initial clustering results. The clustering results include at least one set of use cases.
[0096] In this embodiment of the application, existing clustering methods can be used to cluster multiple use cases, such as the affine propagation clustering method. The specific process of this clustering method is described below.
[0097] In one possible embodiment, step S103, which involves clustering multiple use cases based on a similarity matrix to obtain initial clustering results, may include the following steps A1-A3:
[0098] A1. For any two use cases among multiple use cases, determine the initial clustering parameters between the two use cases based on the similarity matrix.
[0099] The clustering parameters can include membership degree and attractiveness. The membership degree and attractiveness of any two use cases can be calculated based on the similarity matrix. For example, the membership degree of use case i and use case j is a(i,j), and the attractiveness is r(i,j). If use case j maximizes a(i,j) + r(i,j), then use case i and use case j belong to the same class, and use case j is the cluster center of use case i. Specifically, a(i,j) and r(i,j) can be calculated using the following equations (2)-(5):
[0100] r(i,j) = s(i,j) - max k≠j {a(i,k)+s(i,k)} (2)
[0101] r(i, i) = s(i, i) - max k≠i {a(i,k)+s(i,k)} (3)
[0102] a(i,j)=min{0,r(j,j)+∑ k≠i,j max(0, r(k, j))} (4)
[0103] a(i, i)=∑ k≠i max(0, r(k, i)) (5)
[0104] A2. For any two use cases among multiple use cases, perform the following operations using an iterative update method until the second iteration termination condition is met: Based on the adjusted parameters and the clustering parameters between the two use cases, obtain the updated clustering parameters between the two use cases.
[0105] The adjustment parameters can be set as needed. For example, the adjustment parameter is the damping factor λ, where λ∈(0,1]. The speed of iteration can be controlled by adjusting the size of the damping factor. Optionally, λ can be selected as 0.5.
[0106] The calculation method for the nth iteration is shown in equations (6) and (7) below:
[0107] r n (i,j)=(1-λ)[s(i,j)-max k≠j {a(i,k)+s(i,k)}]+λr n-1 (i, j) (6)
[0108] a n (i,j)=(1-λ)*min{0,r(j,j)+∑ k≠i,j max(0, r(k, j))}+λa n-1 (i, j) (7)
[0109] A3. Based on the clustering parameters between every two test cases obtained recently, obtain the initial clustering results.
[0110] The termination condition for the second iteration in step A2 above can be that the number of iterations reaches a set number and the cluster centers no longer change. Multiple use cases can be clustered using the membership and attraction between any two use cases to obtain multiple use case sets, each containing a cluster center.
[0111] Step S104: Perform the following operations using an iterative update method until the first iteration termination condition is met: adjust the similarity matrix based on the supervision information and clustering results, and perform clustering processing on multiple use cases based on the adjusted similarity matrix to obtain the current clustering results; wherein, the supervision information includes the association relationship between use cases in multiple use cases.
[0112] The termination condition for the first iteration can be set as needed.
[0113] In one possible embodiment, the relationships between use cases in the supervision information include: pairwise constraint information initially set for the program under test, and a pre-set use case knowledge base.
[0114] When regression testing is required on the program to be tested, pairwise constraint information can be set based on the full set of test cases. The pairwise constraint information includes at least multiple pairs of positive test cases with positive correlation. If two test cases have a positive correlation, it means that these two test cases need to appear in the same regression test, and these two test cases are treated as a positive test case pair. In addition, the pairwise constraint information can also include multiple pairs of negative test cases with negative correlation. If two test cases have a negative correlation, it means that these two test cases will not appear in the same regression test, and these two test cases are treated as a negative test case pair.
[0115] The use case knowledge base can be maintained long-term by experienced testers and records key use case relationships. Specifically, it can include positive and negative relationships between use cases. Two use cases with a positive relationship mean that they need to appear in the same regression test, while two use cases with a negative relationship mean that they will not appear in the same regression test.
[0116] Step S104 involves adjusting the similarity matrix based on supervised information and clustering results, which may specifically include the following steps B1-B3:
[0117] B1. Repeat the following operations until the first termination condition is met: Based on pairwise constraint information, use case knowledge base and clustering results, select positive use case pairs with positive association from multiple use cases and update them in the pairwise constraint information.
[0118] The first termination condition can be that the number of positive test case pairs selected from multiple test cases reaches a first set number. This first set number can be set as needed and is not limited here.
[0119] Optionally, based on pairwise constraint information and clustering results, two use cases that satisfy the second preset condition are selected from multiple use cases; if it is determined from the use case knowledge base that two use cases have a negative association, then the two use cases are treated as a negative use case pair and updated in the pairwise constraint information.
[0120] Specifically, two use cases that satisfy the second preset condition can be selected from multiple use cases in the following way: For any two use cases among multiple use cases, if the two use cases belong to different use case sets in the clustering results and the pairwise constraint information does not include the two use cases, then the two use cases are determined to satisfy the second preset condition.
[0121] For example, the temporary positive association matrix Mt is initialized to be empty, the temporary positive association relation Dm is empty, and the number of learned pair constraints (including positive use case pairs and negative use case pairs) L = 0.
[0122] Sort the elements of the similarity matrix R in descending order and record the sorting result as S. Use res(x)i () represents the clustering result of use case i. In the above sorting result S, find the first data pair x that satisfies the following condition in ascending order. i and x j : s(i,j)≠0, res(x) i )≠res(x j )
[0123] Actively query the use case knowledge base; if x is confirmed... i and x j If the two corresponding use cases have a positive association, then these two use cases are considered a positive use case pair, and (x) i x j Add M t s(i,j) is stored in D M Then update s(i,j) = 0 to S and record L = L + 1. Sort the updated S again in descending order and continue positive association learning until L = 0.5N (assuming that the number of pair constraints to be learned is N, and the number of positive use case pairs and negative use case pairs is the same).
[0124] B2. Repeat the following operations until the second termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select negative use case pairs with negative associations from multiple use cases and update them in the pairwise constraint information.
[0125] The second termination condition can be that the number of negative test case pairs selected from multiple test cases reaches a second set number. This second set number can be set as needed and is not limited here.
[0126] Optionally, based on pairwise constraint information and clustering results, two use cases that satisfy the third preset condition are selected from multiple use cases; if it is determined from the use case knowledge base that two use cases have a positive correlation, then the two use cases are taken as a positive use case pair.
[0127] Specifically, two use cases that satisfy the third preset condition can be selected from multiple use cases in the following way: For any two use cases among multiple use cases, if the two use cases belong to the same use case set in the clustering result and the pairwise constraint information does not include the two use cases, then the two use cases are determined to satisfy the third preset condition.
[0128] For example, the temporary negative association matrix Ct is initialized to be empty, the temporary negative association relationship Dc is empty, and the number of learned pairwise constraints L is the number of learned positive example pairs. The elements in the similarity matrix R are sorted from largest to smallest. In the resulting sorting result S, the first data pair x that satisfies the following condition is searched from largest to smallest. i and x j: s(i,j)≠-∞, res(x) i ) = res(x j )
[0129] Actively query the use case knowledge base; if x is confirmed... i and x j If the two corresponding use cases are negatively correlated, then these two use cases are treated as a negative use case pair, and (x) i x j Add C t The initial s(i,j) is stored in D. c The initial s(i,j) is updated to -∞ and recorded as L = L+1. The updated S is then reordered in descending order, and negative association learning continues until L = N.
[0130] B3. For any two use cases among multiple use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then update the similarity between the two use cases to the first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then update the similarity between the two use cases in the similarity matrix to the second preset value.
[0131] The first and second preset values can be set as needed. Optionally, the first preset value can be 0 and the second preset value can be -∞, without any limitation.
[0132] Furthermore, in step S104, multiple use cases are clustered based on the adjusted similarity matrix to obtain the current clustering result. The implementation process is similar to that of step S103 above, and will not be repeated here.
[0133] Step S105: Select the set of test cases that meet the first preset condition from the latest clustering results obtained, and generate test cases.
[0134] Optionally, step S105 can be performed in one or both of the following ways:
[0135] Method 1: Select a set of test cases from the latest clustering results that includes any positive test case pair from the initial settings.
[0136] Method 2: From the latest clustering results, select a set of test cases where the target execution parameters of the cluster centers reach the set parameter values.
[0137] The test case generation method of this application embodiment will be described in detail below.
[0138] The test case generation method in this application embodiment specifically includes the following implementation process:
[0139] 1. Instrument the source code of the service and release a version for testing.
[0140] The version to be tested can be understood as the program to be tested in the above embodiments.
[0141] 2. Collect the target execution parameters of the test cases and construct a similarity matrix.
[0142] Typically, for the services mentioned above, the services are run periodically and all test cases are executed automatically. By instrumenting the source code, the correlation parameters between the test cases and the execution status of the changed code (i.e., the changed program) can be obtained, such as real-time stack information, code execution frequency, method block coverage, etc. These correlation parameters are used as target execution parameters.
[0143] Based on the target execution parameters of each use case, the similarity between any two use cases is measured using the negative squared Euclidean distance to obtain a similarity matrix, as shown in Equation (1) of the above embodiment.
[0144] 3. Set positive and negative use case pairs for all use cases, and construct positive and negative association matrices.
[0145] A positive use case pair consists of two use cases with positive correlation, and a negative use case pair consists of two use cases with negative correlation. If two use cases i and j are positively correlated, it means that they are highly correlated and should appear in the same regression test. Their similarity can be denoted as s(i,j) = 0, and a positive correlation matrix M is constructed based on all positive use case pairs. If two use cases i and j are negatively correlated, it means that they are highly correlated and will almost never appear in the same regression test. Their similarity can be denoted as s(i,j) = -∞, and a negative correlation matrix C is constructed based on all negative use case pairs.
[0146] 4. Use a similarity matrix to cluster all test cases.
[0147] Based on the similarity matrix R, the affiliation degree a(i,j) and attraction degree r(i,j) of any two use cases i and j can be calculated. If x j To maximize a(i,j) + r(i,j), then x i and x j Belonging to the same category and x j For x i The cluster centers. The clustering algorithm process is as follows: Figure 2 As shown, the specific iterative process includes the following steps S201-S204:
[0148] Step S201: Based on the similarity matrix, calculate the degree of belonging and attractiveness between use cases, as detailed in equations (2) to (5) of the above embodiments.
[0149] Step S202: Iteratively update the attribution and attraction between use cases. The calculation method for the nth iteration is shown in Equations (6) and (7) in the above embodiments.
[0150] Step S203: Determine whether the iteration has reached the convergence condition. If yes, proceed to step S204. If no, return to step S202.
[0151] The convergence condition can be understood as the first iteration termination condition in the above embodiments, including the number of iterations reaching a set number and the cluster center points no longer changing.
[0152] Step S204: Obtain the clustering results.
[0153] Specifically, clustering results are obtained based on the affiliation and attraction between use cases updated in the last iteration.
[0154] 5. Adjust the similarity matrix and clustering results using supervised information.
[0155] The supervised information comprises two parts: pairwise constraint information and a use case knowledge base. The pairwise constraint information was obtained in step 3 above, and the use case knowledge base is maintained and records key use case relationships by experienced testers. Combined with the supervised information, the clustering algorithm can further filter out use cases that match the business scenario. The semi-supervised clustering algorithm process with added supervised information is as follows: Figure 3 As shown, the specific process includes the following steps S301-S310:
[0156] Step S301: Obtain the similarity matrix R, the positive correlation matrix M, and the negative correlation matrix C, and set the number N of pairwise constraints to be learned.
[0157] In step 4 above, the affine propagation clustering algorithm is used based on the similarity matrix R to cluster all test cases, obtaining the clustering results, and then res(x) is used to perform the clustering. i Let S represent the clustering result for use case i. Sort the elements in the similarity matrix R from largest to smallest and record the sorting result as S.
[0158] Step S302: Initialize the temporary positive association matrix Mt and the temporary negative association matrix Ct to be empty, the temporary positive association relation Dm and the temporary negative association relation Dc to be empty, and the number of learned pairwise constraints L = 0.
[0159] Step S303: Positive association learning. If a positive use case pair is found, update Mt and Dm, and L = L + 1.
[0160] Specifically, in the sorted results S above, find the first data pair x that satisfies the following condition in ascending order. i and x j : s(i,j)≠0, res(x)i )≠res(x j )
[0161] Actively query the use case knowledge base; if x is confirmed... i and x j If the two corresponding use cases have a positive association, then these two use cases are considered a positive use case pair, and (x) i x j Add M t s(i,j) is stored in D M Then update s(i,j) = 0 to S, and record L = LS1. Sort the updated S in descending order and continue positive association learning.
[0162] In step S304, does L reach 0.5N? If yes, continue to step S305; otherwise, return to step S303.
[0163] If we assume that the number of positive and negative use case pairs is the same in the pairwise constraints to be learned, then the termination condition for positive association learning is L = 0.5N.
[0164] Step S305, negative association learning: if a negative use case pair is found, then update Ct, Dc, and L = L + 1.
[0165] Specifically, in the sorted result S above, find the first data pair x that satisfies the following condition in descending order. i and x j : s(i,j)≠-∞, res(x) i ) = res(x j ),
[0166] Actively query the use case knowledge base; if x is confirmed... i and x j If the two corresponding use cases are negatively correlated, then these two use cases are treated as a negative use case pair, and (x) i x j Add C t The initial s(i,j) is stored in D. c The initial s(i,j) is updated to -∞ and recorded as L = L+1. The updated S is then reordered in descending order, and negative association learning continues.
[0167] In step S306, does L reach N? If yes, continue to step S307; otherwise, return to step S305.
[0168] The termination condition for negative association learning is L = N.
[0169] Step S307: Adjust the positive correlation matrix M and the negative correlation matrix C.
[0170] Specifically, the aforementioned temporary positive correlation matrix M t Positive use cases are added to the positive correlation matrix M, and after merging, M is adjusted according to the following rules: If Then (x) i x j )∈M.
[0171] Similarly, the temporary negative correlation matrix C t The negative use cases are added to the negative association matrix C and adjusted.
[0172] Step S308: Adjust the similarity matrix R, and cluster all use cases based on the adjusted similarity matrix R.
[0173] Where, if x i and x j If it belongs to the positive correlation matrix M, then adjust the similarity in the similarity matrix R so that s(i,j) = 0 & s(j,i) = 0; if x i and x j If the data belongs to the negative correlation matrix C, then adjust the similarity in the similarity matrix R by setting s(i,j) = -∞ and s(j,i) = -∞. Then, re-cluster all test cases using the affine propagation clustering algorithm.
[0174] Step S309: Determine whether the learning termination condition has been met. If yes, continue to step S310; otherwise, return to step S302.
[0175] Specifically, calculate the above D M and D c The mean values are A M and A c If A M -A c If the value is greater than or equal to 0, then the learning termination condition is met. This learning termination condition can be understood as the first iteration termination condition in the above embodiment.
[0176] Step S310: Output the final clustering result.
[0177] 6. Generate test cases. Analyze the last obtained clustering results. Test case sets that meet the following conditions will be selected as regression test case sets: test case sets containing initial positive test case pairs, and test case sets whose target execution parameters for cluster centers meet the conditions.
[0178] The conditions for the target execution parameters to be met can be that the target execution parameters reach the set parameters, or that the target execution parameters are at their maximum.
[0179] The test case generation method provided in this application has at least the following advantages:
[0180] 1. Use code instrumentation to obtain test case execution parameters, quantify the relationship between each test case and service incremental changes, and provide reliable assurance for test case generation by providing data feedback on the impact of incremental changes on business test cases, thus avoiding omissions in test scenarios.
[0181] Second, by introducing an affine propagation clustering algorithm to train test cases, the problem of large workload in test case screening under complex business scenarios is solved, test case classification is automated, manual operation is reduced, testing efficiency is improved, and testing costs are reduced.
[0182] Third, using semi-supervised clustering algorithms can effectively avoid the limitations of traditional clustering algorithms. For special scenarios where the similarity is high but they belong to different classes, or the similarity is low but they belong to the same class, the supervision information can be used to effectively avoid these problems.
[0183] This application's embodiments effectively combine human testing experience with intelligent algorithms by introducing supervisory information. In particular, for special scenarios involving changes in upstream and downstream businesses, where incremental service changes cannot be used to filter test cases, the required test cases can still be effectively filtered out by using testing experience to screen smoke test cases and set pairwise constraints. The long-term maintained test case knowledge base can also avoid the omission of occasional business scenarios.
[0184] The test case generation method of this application embodiment is described below with specific examples.
[0185] 1) Instrument the source code of the service and package it into a version to be tested.
[0186] 2) Testers select smoke test cases based on business scenarios and set them as positive association pair constraints. They can also select negative association pair constraints based on actual conditions and input the constraints into the algorithm training module.
[0187] Smoke test cases are used to perform smoke tests on the version under test. Smoke testing mainly tests the most basic functions of the version under test to ensure that the most basic process can be completed in order to carry out subsequent tests.
[0188] 3) Obtain the target execution parameters of the use cases, generate a similarity matrix, and obtain the clustering results through a semi-supervised affine clustering algorithm based on the supervised information.
[0189] 4) Based on the clustering results, select the set of test cases containing the initial positive correlation constraint pairs and the set of test cases with the optimal cluster center parameter values as the regression test case set.
[0190] This application employs a semi-supervised clustering algorithm, effectively avoiding the limitations of traditional clustering algorithms. It can effectively avoid special scenarios where high similarity exists but the clusters are different, or low similarity exists but the clusters are the same, through the use of supervisory information. By introducing supervisory information, it effectively combines manual testing experience with intelligent algorithms. Particularly useful for special scenarios involving changes to upstream and downstream services, where it's impossible to rely on the changed code of the service under test to select test cases, it can still effectively select the required test cases by filtering smoke test cases through testing experience and setting pairwise constraints. Furthermore, the long-term maintained test case knowledge base can prevent the omission of occasional business scenarios.
[0191] Furthermore, using semi-supervised clustering algorithms for test case generation can adapt to various complex business scenarios and efficiently generate test cases. If there are incremental changes to the service, all test cases involving the changes can be intuitively and quantitatively filtered out through test case execution parameters, covering as many scenarios as possible and reducing test case omissions. If upstream or downstream services change, supervisory information can also be set through human experience to provide reliable assurance for test case generation. By introducing supervisory information, the experience reserves of testers are fully utilized. Setting pairwise constraints can ensure coverage of smoke scenarios, and querying the test case knowledge base can effectively avoid the recurrence of critical issues. Combining supervisory information with clustering algorithms can improve testing efficiency, reduce testing costs, and maximize the subjective initiative of testers.
[0192] Based on the same inventive concept, this application provides a test case generation device, such as... Figure 4 As shown, the test case generation device includes a parameter acquisition module 41, a similarity determination module 42, a clustering module 43, a supervision module 44, and a generation module 45.
[0193] The parameter acquisition module 41 is used to acquire the target execution parameters of each of the multiple test cases in the program under test. The target execution parameters are obtained by executing the corresponding test cases during the operation of the program under test.
[0194] The similarity determination module 42 is used to determine the similarity of target execution parameters between any two use cases in multiple use cases and obtain a similarity matrix;
[0195] Clustering module 43 is used to cluster multiple use cases based on a similarity matrix to obtain an initial clustering result, which includes at least one set of use cases.
[0196] The supervision module 44 is used to perform the following operations in an iterative update manner until the first iteration termination condition is met: adjust the similarity matrix based on the supervision information and clustering results, and perform clustering processing on multiple use cases based on the adjusted similarity matrix to obtain the current clustering result; wherein, the supervision information includes the association relationship between use cases in multiple use cases;
[0197] The generation module 45 is used to select a set of test cases that meet the first preset condition from the latest clustering results and generate test cases.
[0198] In one possible embodiment, clustering module 43 is further configured to:
[0199] For any two use cases from a set of multiple use cases, the initial clustering parameters between the two use cases are determined based on the similarity matrix.
[0200] For any two use cases among multiple use cases, perform the following operations in an iterative update manner until the second iteration termination condition is met: Based on the adjusted parameters and the clustering parameters between the two use cases, obtain the updated clustering parameters between the two use cases;
[0201] Based on the clustering parameters between each pair of newly obtained use cases, the initial clustering results are obtained.
[0202] In one possible embodiment, the association between multiple use cases in the supervision information includes: pairwise constraint information initially set for the program under test, and a pre-set use case knowledge base; wherein, the pairwise constraint information includes at least multiple pairs of positively associated use cases, and the use case knowledge base includes positive association relationships between use cases and negative association relationships between use cases;
[0203] When adjusting the similarity matrix based on supervised information and clustering results, the supervised module 44 is also used for:
[0204] Repeat the following operations until the first termination condition is met: Based on pairwise constraint information, use case knowledge base, and clustering results, select positive use case pairs with positive association from multiple use cases and update them in the pairwise constraint information;
[0205] Repeat the following operations until the second termination condition is met: Based on pairwise constraint information, use case knowledge base, and clustering results, select negative use case pairs with negative associations from multiple use cases and update them in the pairwise constraint information;
[0206] For any two use cases among multiple use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then the similarity between the two use cases is updated to a first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then the similarity between the two use cases in the similarity matrix is updated to a second preset value.
[0207] In one possible embodiment, when selecting positive use case pairs with positive correlation from multiple use cases based on pairwise constraint information, a use case knowledge base, and clustering results, the supervision module 44 is further configured to:
[0208] Based on pairwise constraint information and clustering results, two use cases that satisfy the second preset condition are selected from multiple use cases.
[0209] If two use cases are determined to have a positive association based on the use case knowledge base, then the two use cases are considered as a positive use case pair.
[0210] When selecting negative use case pairs with negative associations from multiple use cases based on pairwise constraint information, use case knowledge base, and clustering results, the supervision module 44 is also used for:
[0211] Based on pairwise constraint information and clustering results, two use cases that satisfy the third preset condition are selected from multiple use cases.
[0212] If two use cases are determined to have a negative association based on the use case knowledge base, then the two use cases are treated as a negative use case pair and updated in the pair constraint information.
[0213] In one possible embodiment, when selecting two use cases that satisfy the second preset condition from multiple use cases based on pairwise constraint information and clustering results, the supervision module 44 is further configured to:
[0214] For any two use cases among multiple use cases, if the two use cases belong to different use case sets in the clustering results and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the second preset condition.
[0215] When selecting two use cases that satisfy the third preset condition from multiple use cases based on pairwise constraint information and clustering results, the supervision module 44 is also used to:
[0216] For any two use cases among multiple use cases, if the two use cases belong to the same use case set in the clustering results, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases meet the third preset condition.
[0217] In one possible embodiment, the generation module 45 is further configured to:
[0218] From the latest clustering results, select a set of test cases that includes any positive test case pair from the initial settings; and / or
[0219] From the latest clustering results, select the set of test cases where the target execution parameters reach the set parameter values from the cluster centers.
[0220] In one possible embodiment, the target execution parameters for each use case include: execution association parameters between the use case and the modified program corresponding to the program under test;
[0221] Among them, the execution-related parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage.
[0222] Based on the same inventive concept, this application provides an electronic device that can realize the function of the test case generation device described above. Please refer to... Figure 5 The device includes a processor 501 and a memory 502, the memory 502 being used to store program instructions; the processor 501 is used to call the program instructions stored in the memory 502 and execute the steps included in any of the test case generation methods in the above embodiments according to the obtained program instructions.
[0223] This application embodiment does not limit the specific connection medium between the memory 502 and the processor 501. For example, the memory 502 and the processor 501 are connected via a bus, which can be divided into an address bus, a data bus, a control bus, etc.
[0224] The memory 502 may include read-only memory (ROM) and random access memory (RAM), and may also include non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0225] The processor 501 mentioned above can be a general-purpose processor, including a central processing unit, a network processor (NP), etc.; it can also be a digital signal processing (DSP), an application-specific integrated circuit, a field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc.
[0226] Based on the same inventive concept, embodiments of this application provide a computer-readable storage medium. The computer program product includes computer program code, which, when run on a computer, causes the computer to execute any of the test case generation methods discussed above. Since the principle by which the above-described computer-readable storage medium solves the problem is similar to that of the test case generation method, the implementation of the above-described computer-readable storage medium can be found in the implementation of the method; repeated details will not be elaborated further.
[0227] In specific implementation, computer storage media can include: Universal Serial Bus Flash Drive (USB), portable hard drive, Read-Only Memory (ROM), Random Access Memory (RAM), magnetic disk or optical disk, and other storage media that can store program code.
[0228] Based on the same inventive concept, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to execute any of the test case generation methods discussed above. Since the principle by which the above computer program product solves the problem is similar to that of the test case generation method, the implementation of the above computer program product can refer to the implementation of the method, and repeated details will not be described again.
[0229] Computer program products may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0230] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0231] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0232] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0233] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of user-operated steps to be executed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0234] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A test case generation method, characterized in that, include: Obtain the target execution parameters for each of the multiple test cases in the program under test. The target execution parameters for each test case include: execution association parameters between the test case and the modified program corresponding to the program under test. The execution association parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage. Determine the similarity of the target execution parameters between any two use cases from the plurality of use cases, and obtain a similarity matrix; The multiple use cases are clustered based on the similarity matrix to obtain an initial clustering result, which includes at least one set of use cases. The following operations are performed using an iterative update method until the first iteration termination condition is met: the similarity matrix is adjusted based on the supervised information and the clustering results, and the multiple use cases are clustered based on the adjusted similarity matrix to obtain the current clustering result; Select a set of test cases that meet the first preset condition from the latest clustering results obtained, and generate test cases; The relationship between the test cases in the multiple test cases in the supervision information includes: pair constraint information initially set for the program under test and a pre-set test case knowledge base. The pair constraint information includes at least multiple pairs of positive test cases with positive associations, and the test case knowledge base includes positive associations between test cases and negative associations between test cases. The adjustment of the similarity matrix based on supervised information and the clustering results includes: Repeat the following operations until the first termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select positive use case pairs with positive associations from the plurality of use cases and update them in the pairwise constraint information; Repeat the following operations until the second termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select negative use case pairs with negative associations from the plurality of use cases and update them in the pairwise constraint information; For any two use cases among the plurality of use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then the similarity of the two use cases is updated to a first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then the similarity of the two use cases in the similarity matrix is updated to a second preset value.
2. The method according to claim 1, characterized in that, The step of clustering the multiple use cases based on the similarity matrix to obtain initial clustering results includes: For any two use cases among the plurality of use cases, the initial clustering parameters between the two use cases are determined based on the similarity matrix; For any two of the multiple use cases, perform the following operations in an iterative update manner until the second iteration termination condition is met: Based on the adjustment parameters and the clustering parameters between the two use cases, obtain the updated clustering parameters between the two use cases; The initial clustering results are obtained based on the clustering parameters between each pair of newly obtained use cases.
3. The method according to claim 1, characterized in that, The step of selecting positive use case pairs with positive correlation from the plurality of use cases based on the pairwise constraint information, the use case knowledge base, and the clustering results includes: Based on the pairwise constraint information and the clustering results, two use cases that satisfy the second preset condition are selected from the plurality of use cases; If the two use cases are determined to have a positive association based on the use case knowledge base, then the two use cases are considered as a positive use case pair. Based on the pairwise constraint information, the use case knowledge base, and the clustering results, negative use case pairs with negative associations are selected from the plurality of use cases, including: Based on the pairwise constraint information and the clustering results, two use cases that satisfy the third preset condition are selected from the plurality of use cases; If the two use cases are determined to have a negative association based on the use case knowledge base, then the two use cases are treated as a negative use case pair and updated in the pair constraint information.
4. The method according to claim 3, characterized in that, The step of selecting two use cases that satisfy the second preset condition from the plurality of use cases based on the pairwise constraint information and the clustering results includes: For any two use cases among the plurality of use cases, if the two use cases belong to different use case sets in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the second preset condition. The step of selecting two use cases that satisfy the third preset condition from the plurality of use cases based on the pairwise constraint information and the clustering results includes: For any two use cases among the plurality of use cases, if the two use cases belong to the same use case set in the clustering result, and the pairwise constraint information does not include the two use cases, then it is determined that the two use cases satisfy the third preset condition.
5. The method according to claim 1, characterized in that, The step of selecting a set of use cases that meet the first preset condition from the latest clustering results includes: From the latest clustering results, select a set of use cases that includes any one of the positive use case pairs from the initial settings; and / or From the latest clustering results, select the set of test cases where the target execution parameters of the cluster centers reach the set parameter values.
6. A test case generation device, characterized in that, include: The parameter acquisition module is used to acquire the target execution parameters of each test case in multiple test cases of the program under test. The target execution parameters of each test case include: execution association parameters between the test case and the modified program corresponding to the program under test. The execution association parameters include at least one of the following: real-time stack information, code execution frequency, and method block coverage. The similarity determination module is used to determine the similarity of target execution parameters between any two use cases among the plurality of use cases, and obtain a similarity matrix; A clustering module is used to cluster the multiple use cases based on the similarity matrix to obtain an initial clustering result, wherein the clustering result includes at least one set of use cases; The supervision module is used to perform the following operations in an iterative update manner until the first iteration termination condition is met: adjust the similarity matrix based on the supervision information and the clustering results, and perform clustering processing on the multiple use cases based on the adjusted similarity matrix to obtain the current clustering result; The generation module is used to select a set of test cases that meet the first preset condition from the latest clustering results and generate test cases. The relationship between the test cases in the multiple test cases in the supervision information includes: pair constraint information initially set for the program under test and a pre-set test case knowledge base. The pair constraint information includes at least multiple pairs of positive test cases with positive associations, and the test case knowledge base includes positive associations between test cases and negative associations between test cases. When adjusting the similarity matrix based on the supervision information and the clustering results, the supervision module is specifically used for: Repeat the following operations until the first termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select positive use case pairs with positive associations from the plurality of use cases and update them in the pairwise constraint information; Repeat the following operations until the second termination condition is met: Based on the pairwise constraint information, the use case knowledge base, and the clustering results, select negative use case pairs with negative associations from the plurality of use cases and update them in the pairwise constraint information; For any two use cases among the plurality of use cases, if the two use cases belong to a positive use case pair in the updated pair constraint information, then the similarity of the two use cases is updated to a first preset value; if the two use cases belong to a negative use case pair in the updated pair constraint information, then the similarity of the two use cases in the similarity matrix is updated to a second preset value.
7. An electronic device, characterized in that, include: Memory, used to store program instructions; A processor is configured to invoke program instructions stored in the memory and execute the steps of the method according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a computer, cause the computer to perform the method as described in any one of claims 1-5.