Test method and device, electronic equipment and storage medium

By grading and sorting the complexity evaluation index values ​​of functions in the software code files of the automobile industry, and optimizing the test sequence, the development cycle extension problem caused by unreasonable test sequence is solved, and the software development efficiency is improved.

CN120045451APending Publication Date: 2025-05-27GUANGZHOU AUTOMOBILE GROUP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510019474.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-06
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

During the software development process of the automotive industry, due to frequent code iterations and unreasonable code testing sequences, the software development cycle is extended.

Method used

By obtaining the index values ​​of each function in the code file to be tested under multiple complexity evaluation indicators, the function's risk score is determined, and the functions are sorted and tested in the order of risk scores from high to low.

Benefits of technology

Priority is given to testing high-risk functions, expose and fix problems in advance, avoid extending the software development cycle due to unreasonable testing sequence, and improving software development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045451A_ABST
    Figure CN120045451A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of testing, and discloses a testing method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining the index value of each function in a to-be-tested code file under m complexity evaluation indexes, m being a positive integer greater than 1; determining the risk score of each function according to the index value of each function in the to-be-tested code file under the m complexity evaluation indexes; sorting the multiple functions in the to-be-tested code file according to a sequence from high risk score to low risk score to obtain a target sequence; according to the target sequence, the multiple functions in the to-be-tested code file are tested, the function with the higher risk can be tested preferentially, and therefore the software development period can be prevented from being prolonged on the whole.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of testing technology, and in particular to a testing method, device, electronic device and storage medium. Background Art

[0002] During the software development process, developers continuously iterate and update the software code due to changing requirements, bug fixes, and code optimization. These code modifications may introduce new issues or cause the existing code to malfunction. Therefore, regression testing is a crucial and essential step in ensuring code quality. Given the rapid iteration rate and large software scale of the automotive industry, improper code testing sequencing can extend the software development cycle. Therefore, determining the testing sequence to minimize this delay is a pressing technical challenge in related technologies. Summary of the Invention

[0003] In view of this, the embodiments of the present application propose a testing method, device, electronic device and storage medium to solve the problem in the related art that the software development cycle is extended due to unreasonable code testing sequence.

[0004] The embodiments of the present application are implemented using the following technical solutions:

[0005] In the first aspect, an embodiment of the present application provides a testing method, including: obtaining the index value of each function in the code file to be tested under m complexity evaluation indicators, where m is a positive integer greater than 1; determining the risk score of each function according to the index value of each function in the code file to be tested under m complexity evaluation indicators; sorting multiple functions in the code file to be tested in order of risk score from high to low to obtain a target sorting; and testing multiple functions in the code file to be tested according to the target sorting.

[0006] In the second aspect, an embodiment of the present application provides a testing device, including: an indicator value acquisition module, used to obtain the indicator value of each function in the code file to be tested under m complexity evaluation indicators, where m is a positive integer greater than 1; a score determination module, used to determine the risk score of each function in the code file to be tested based on the indicator value of each function in the code file to be tested under m complexity evaluation indicators; a sorting module, used to sort multiple functions in the code file to be tested in order of risk score from high to low, and obtain a target sorting; a testing module, used to test multiple functions in the code file to be tested according to the target sorting.

[0007] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor; a memory, wherein computer instructions are stored in the memory, and when the computer instructions are executed by the processor, the above-mentioned test method is implemented.

[0008] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed by a processor, the above-mentioned testing method is implemented.

[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising computer instructions, which implement the above-mentioned testing method when executed by a processor.

[0010] In this application, considering that the index value of a function in a code file under a complexity evaluation index can reflect the complexity of the function, and the complexity of the function also directly affects the probability of problems occurring in the function during the operation of the function, based on this principle, in the application, the risk score of the function is determined by the index value of each function under m complexity evaluation indicators. The higher the risk score of the function, the higher the probability of problems occurring during the operation of the function. Moreover, m is greater than 1. The risk score of the function is determined by the index values ​​under multiple different complexity evaluation indicators of the function, which can ensure the accuracy of the determined risk score. Afterwards, multiple functions in the code file to be tested are sorted in descending order according to the risk scores to obtain the target sorting; and multiple functions in the code file to be tested are tested according to the target sorting. In this way, it can be ensured that the functions with higher risk scores are tested first, that is, high-risk functions are tested first. In this way, problems of functions with higher risks will be exposed first during the testing process. In the process of testing other subsequent functions, developers can simultaneously troubleshoot and fix problems exposed by the functions tested first. The time for subsequent testing of other functions also ensures that developers have enough time to troubleshoot and fix problems in the functions tested first, which can effectively avoid the extension of the software development cycle due to unreasonable code testing order. While ensuring testing efficiency, the overall software development efficiency can be improved.

[0011] These and other aspects of the present application will become more readily apparent from the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0013] Figure 1 It is a flow chart of a testing method shown in one embodiment of the present application.

[0014] Figure 2FIG. 1 is a flowchart of step 120 according to an embodiment of the present application.

[0015] Figure 3 This is a flowchart of step 230 shown in one embodiment of the present application.

[0016] Figure 4 FIG. 2 is a flow chart of step 240 according to an embodiment of the present application.

[0017] Figure 5 is a flow chart of a testing method according to another embodiment of the present application.

[0018] Figure 6 This is a block diagram of a testing device according to an embodiment of the present application.

[0019] Figure 7 This is a block diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0020] The embodiments of the present application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application and are not to be construed as limiting the present application.

[0021] In order to enable those skilled in the art to better understand the present invention, the following will provide a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0022] In the following description, the terms "first\second" and the like are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understandable that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0023] The "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. In the following description, it is mentioned that "some embodiments or some embodiment modes" describe a subset of all possible embodiments, but it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.

[0024] Figure 1 The method of the present application can be executed by an electronic device, such as a server, or other terminal with processing capabilities, such as Figure 1 As shown, the method includes steps 110 to 140:

[0025] Step 110: Obtain the index value of each function in the code file to be tested under m complexity evaluation indexes, where m is a positive integer greater than 1.

[0026] The code file under test is the code file to be tested. It can be a newly written code file or a code file that has undergone code updates. Functions in the code file under test are reusable code blocks that implement specific functionality. Of course, different functions implement different functions.

[0027] Complexity evaluation index refers to an indicator used to evaluate the complexity of a function. Different complexity evaluation indexes represent different evaluation dimensions. In this application, complexity evaluation indicators include cyclomatic complexity, the number of function parameters, the number of return statements, and the depth of function nesting. Among them, cyclomatic complexity is also called conditional complexity. It can usually be used to measure the complexity of a code block's decision structure. Cyclomatic complexity is equal to the number of independent paths in a function. The higher the cyclomatic complexity, the more complex the function is, and the more difficult it is to test and maintain. The number of function parameters refers to the number of parameters passed into a single function. The number of return statements refers to the number of return points or exit points in a single function. It has nothing to do with whether the function declares a return value, but is related to the number of return statements. The more return statements in a function (i.e., the number of return statements), the higher the complexity of the function and the greater the maintenance difficulty. Function nesting depth refers to the depth of the nesting level of conditional statements (such as if statements) or loops (such as for loops) in a function.

[0028] The m complexity evaluation indicators are at least two of cyclomatic complexity, number of function parameters, number of return statements and function nesting depth. For example, they can be any two of cyclomatic complexity, number of function parameters, number of return statements and function nesting depth; or any three of cyclomatic complexity, number of function parameters, number of return statements and function nesting depth; or four of cyclomatic complexity, number of function parameters, number of return statements and function nesting depth.

[0029] Step 120 : determining a risk score for each function in the code file to be tested based on the index value of each function under the m complexity evaluation indexes.

[0030] The risk score of a function is an evaluation of the risk of the function. The higher the risk score of a function, the higher the probability that problems will occur during the test.

[0031] In some embodiments, the index values ​​of a function under m complexity evaluation indicators can be weighted, and the weighted result can be used as the risk score of the function. Generally speaking, the higher the index value of a function under a complexity evaluation indicator, the higher the risk of the function, that is, the higher the probability of failure during the test. The weighting coefficient for each complexity evaluation indicator can be pre-set, or it can be used as the weighting coefficient of the complexity evaluation indicator according to the weight of the complexity evaluation indicator described below.

[0032] In other embodiments, Figure 2 As shown, step 120 includes the following steps 210 to 240:

[0033] Step 210 : construct an indicator matrix according to the indicator value of each function in the code file to be tested under m complexity evaluation indicators.

[0034] Specifically, the index values ​​of multiple functions in the code file to be tested under m complexity evaluation metrics are arranged in rows and columns to form an index matrix. The multiple elements in the same column of the index matrix represent the index values ​​of the same function under m complexity evaluation metrics. Correspondingly, the multiple elements in the same row represent the index values ​​of different functions under the same complexity evaluation metric.

[0035] Alternatively, multiple elements in the same row of the indicator matrix represent the index values ​​of the same function under m complexity evaluation indicators, and correspondingly, multiple elements in the same column represent the index values ​​of different functions under the same complexity evaluation indicator. For example, assuming that the total number of functions in the code file to be tested is n, the indicator matrix X can be expressed as:

[0036]

[0037] Among them, x ijRepresents the index value of the i-th function in the code file to be tested under the j-th complexity evaluation index, where i∈[1,n], j∈[1,m].

[0038] Step 220 , standardize the indicator matrix to obtain a standardized indicator matrix, where the standardized indicator matrix includes standardized values ​​of each indicator value.

[0039] The index value x of the i-th function in the code file to be tested under the j-th complexity evaluation index ij It can be standardized according to the following formula to obtain the standardized value y ij :

[0040]

[0041] In the case where the element in the i-th row and j-th column of the indicator matrix is ​​the index value of the i-th function in the code file to be tested under the j-th complexity evaluation index, the element in the i-th row and j-th column of the standardized indicator matrix is ​​x ij The standardized value y obtained after standardization ij , the standardized indicator matrix Y can be expressed as:

[0042]

[0043] By standardizing the indicator values ​​in the indicator matrix, the indicator values ​​under different complexity evaluation indicators can be transformed into the same fixed interval, avoiding the inaccurate weights for each complexity evaluation indicator due to the large differences in the value ranges of the indicator values ​​under different complexity evaluation indicators.

[0044] Step 230: Determine the weight of each complexity evaluation indicator according to the standardized indicator matrix.

[0045] In some embodiments, based on the standardized indicator matrix, for each complexity evaluation indicator, the average of multiple standardized values ​​under the complexity evaluation indicator can be calculated to obtain the average standardized value corresponding to each complexity evaluation indicator; and the sum of the average standardized values ​​corresponding to m complexity evaluation indicators can be calculated as a reference value; then, for each complexity evaluation indicator, the ratio of the average standardized value corresponding to the complexity evaluation indicator to the reference value is used as the weight of the complexity evaluation indicator.

[0046] In other embodiments, based on the standardized indicator matrix, for each complexity evaluation indicator, the mean of multiple standardized values ​​under the complexity evaluation indicator can be calculated to obtain the average standardized value corresponding to each complexity evaluation indicator; and the sum of the squares of the average standardized values ​​corresponding to m complexity evaluation indicators can be calculated to obtain a first reference value, and the arithmetic square root of the first reference value can be calculated as the second reference value; thereafter, for each complexity evaluation indicator, the ratio of the average standardized value corresponding to the complexity evaluation indicator to the second reference value is used as the weight of the complexity evaluation indicator.

[0047] In other embodiments, Figure 3 As shown, step 230 may include the following steps 310 to 340:

[0048] Step 310: Calculate the probability of each standardized value under the corresponding complexity evaluation index according to the standardized index matrix.

[0049] Specifically, for the index value x of the i-th function in the code file to be tested under the j-th complexity evaluation index ij The corresponding standardized value y ij , the normalized value y can be calculated according to the following formula 4 ij The probability p under the complexity evaluation index ij :

[0050]

[0051] It is understandable that the normalized value y ij The complexity evaluation index it belongs to is the j-th complexity evaluation index. Represents the sum of the standardized values ​​of n functions under the jth complexity evaluation index.

[0052] Step 320 : For each complexity evaluation indicator, determine the information entropy of each complexity evaluation indicator according to a plurality of standardized values ​​under the complexity evaluation indicator.

[0053] In some embodiments, the information entropy e of the j-th complexity evaluation index can be calculated according to the following formula 5: j :

[0054]

[0055] In other embodiments, to ensure that the information entropy of each complexity evaluation index falls between [0, 1], the information entropy e of the jth complexity evaluation index can be calculated according to the following formula 6: j :

[0056]

[0057] Since in the case of j∈[1,m], The maximum value of is lnn, therefore, the information entropy e of the j-th complexity evaluation index calculated according to formula 6 is j It falls in the interval [0, 1].

[0058] Step 330: Determine the utility value of each complexity evaluation indicator based on the information entropy of each complexity evaluation indicator.

[0059] The higher the information entropy of a complexity evaluation indicator, the less information the function fed back by the complexity indicator. Therefore, the utility value of the complexity evaluation indicator is negatively correlated with the information entropy of the complexity evaluation indicator.

[0060] In some embodiments, if the information entropy e of the jth complexity evaluation index is j It is calculated according to formula 5. The information entropy e of the j-th complexity evaluation index can be first j Normalization is performed so that the normalized information entropy is in [0, 1], and the difference between 1 and the normalized information entropy is used as the utility value of the corresponding complexity evaluation index.

[0061] In some embodiments, if the information entropy e of the jth complexity evaluation index is j It is calculated according to Formula 5. The utility value U of the jth complexity evaluation index can be calculated according to the following Formula 7: j :

[0062] U j =1-e j ; (Formula 7)

[0063] Step 340 , calculate the proportion of the utility value of each complexity evaluation index in the total utility value to obtain the weight of each complexity evaluation index. The total utility value is equal to the sum of the utility values ​​of the m complexity evaluation indicators.

[0064] That is: calculate the weight W of the jth complexity evaluation index according to the following formula 8: j :

[0065]

[0066] Step 240 : Determine the risk score of each function based on the weight of each complexity evaluation index and the index value of each function under the m complexity evaluation indexes.

[0067] In some embodiments, for each function, the index values ​​of the function under m complexity evaluation indicators may be weighted according to the weights of the complexity evaluation indicators to obtain a risk score of the function.

[0068] In some embodiments, as Figure 4As shown, step 240 may include the following steps 410 to 440:

[0069] Step 410: Determine the maximum normalized value and the minimum normalized value under each complexity evaluation index according to the normalized index matrix.

[0070] Continuing with the above example, if the total number of functions in the code file to be tested is n, based on the above standardized indicator matrix Y, the maximum standardized value under the jth complexity evaluation indicator is for:

[0071]

[0072] The minimum standardized value under the j-th complexity evaluation index for:

[0073]

[0074] Step 420 , for each function, determine the maximum index distance of the function based on the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index, as well as the weight of the corresponding complexity evaluation index.

[0075] In some embodiments, the difference between the normalized value of a function under a complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index can be the absolute value of the difference between the normalized value of the function under a complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index, which is used as the first index distance of the function under the complexity index. Afterwards, the first index distances of the function under multiple complexity indicators are weightedly calculated according to the weights of multiple complexity evaluation indicators to obtain the maximum index distance of the function.

[0076] In other embodiments, the maximum index distance of each function may be determined according to the following process:

[0077] 1) Calculate the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index to obtain the first index difference of the function under each complexity evaluation index.

[0078] 2) Calculate the maximum index distance of the function based on the weights of multiple complexity evaluation indicators and the difference of the first index of the function under multiple complexity evaluation indicators.

[0079] That is, the maximum index distance of the i-th function in the code file to be tested can be calculated according to the following formula 11:

[0080]

[0081] in, That is, the first index difference of the i-th function in the code file to be tested under the j-th complexity evaluation index; of course, in other embodiments, As the first indicator difference of the i-th function in the code file to be tested under the j-th complexity evaluation index. W j is the weight of the j-th complexity evaluation index.

[0082] Step 430 : For each function, determine the minimum index distance of the function based on the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index, as well as the weight of the corresponding complexity evaluation index.

[0083] In some embodiments, the difference between the normalized value of a function under a complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index can be the absolute value of the difference between the normalized value of the function under a complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index, which is used as the second index distance of the function under the complexity index. Afterwards, the second index distances of the function under multiple complexity indicators are weightedly calculated according to the weights of multiple complexity evaluation indicators to obtain the minimum index distance of the function.

[0084] In other embodiments, for each function, the minimum index distance of the function may be determined according to the following process:

[0085] ① Calculate the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index to obtain the second index difference of the function under each complexity evaluation index.

[0086] ② Calculate the minimum index distance of the function based on the weights of multiple complexity evaluation indicators and the difference in the second index of the function under multiple complexity evaluation indicators.

[0087] That is, the minimum index distance of the i-th function in the code file to be tested can be calculated according to the following formula 12:

[0088]

[0089] in, That is, the second index difference of the i-th function in the code file to be tested under the j-th complexity evaluation index; of course, in other embodiments, As the second indicator difference of the i-th function in the code file to be tested under the j-th complexity evaluation indicator.

[0090] Step 440 : Determine the risk score of each function based on the maximum indicator distance and the minimum indicator distance of each function.

[0091] In some embodiments, step 440 includes: determining, for each function, a reference indicator distance for the function based on the function's maximum indicator distance and minimum indicator distance; and dividing the function's reference indicator distance by a preset benchmark indicator distance, with the resulting result serving as the function's risk score. The function's reference indicator distance reflects the distribution of the function's maximum indicator distance and minimum indicator distance. In some embodiments, the average of the function's maximum indicator distance and minimum indicator distance may be used as the function's reference indicator distance; in other embodiments, the sum of the function's maximum indicator distance and minimum indicator distance may be used as the function's reference indicator distance.

[0092] In other embodiments, step 440 includes: for each function, dividing the minimum indicator distance of the function by the sum of the indicator distances of the function to obtain a risk score of the function, where the sum of the indicator distances of the function is the sum of the maximum indicator distance and the minimum indicator distance of the function.

[0093] That is, the risk score S of the i-th function in the code file to be tested can be calculated according to the following formula 13: i :

[0094]

[0095] Step 130 , sorting the multiple functions in the code file to be tested in descending order of risk scores to obtain a target sorting.

[0096] Step 140 : testing multiple functions in the code file to be tested according to the target sorting.

[0097] In other words, the target ranking is used as the test order for multiple functions in the code file to be tested. In this way, functions with lower sequence numbers (i.e., higher risk scores) are tested first. Since higher risk scores increase the probability of failure during testing, prioritizing functions with higher risk scores can expose problems in high-risk functions in advance, leaving developers with ample time to fix faults and issues, thereby improving overall software development efficiency.

[0098] In some embodiments, a test case set for each function can be obtained. The test case set for a function includes multiple test cases for testing the function. Then, the test case set of the corresponding function is used to test multiple functions in the code file to be tested according to the target sorting.

[0099] The test case set for a function can be a collection of all the test cases for that function. This is equivalent to performing a full regression test on all functions in the code file under test. Furthermore, testing all functions in the code file under test ensures test coverage.

[0100] In other embodiments, the test case set for a function may be a collection of partial test cases for the function. In this case, the test case set for each function may be determined according to the following process: according to the sequence number of each function in the target sorting, the test case extraction ratio of each function is determined, and the test case extraction ratio is negatively correlated with the sequence number of the corresponding function in the target sorting; according to the test case extraction ratio of each function, test cases are selected from the full test case set of the corresponding function and added to the test case set of the corresponding function.

[0101] The correspondence between the sequence number and the use case extraction ratio can be pre-set. This correspondence satisfies the positive correlation between the use case extraction ratio and the sequence number. In this way, it can be ensured that the function with a smaller sequence number (i.e., higher risk) has a higher use case extraction ratio. In this way, for functions with higher risk, the coverage rate of the test cases involved in the test is higher.

[0102] Based on the correspondence between the set sequence number and the use case extraction ratio, the use case extraction ratio of each function can be determined according to the sequence number of each function in the target ranking. Then, according to the function's use case extraction ratio, test cases are selected from the function's full test case set and added to the corresponding function's test case set, ensuring that the ratio between the number of test cases in the function's test case set and the number of test cases in the function's full test case set is equal to the function's use case extraction ratio.

[0103] Based on the above embodiment, it is achieved that for functions with higher risks, the coverage of the test cases involved in the test is higher. In this way, it is ensured that for functions with higher risks, a larger number of test cases are used for testing, which ensures that possible failures of the function during operation can be fully exposed, facilitating timely repairs.

[0104] In some embodiments, the risk scores of each function can also be combined to determine functions whose risk scores exceed the scoring threshold, and functions whose risk scores do not exceed the scoring threshold. In step 140, in the process of testing multiple functions in the code file to be tested according to the target sorting, if the next function to be tested determined by the target sorting is used as the target function to be tested, if the risk score of the target function to be tested exceeds the scoring threshold, the target function to be tested is tested using the full test case set of the target function to be tested; if the risk score of the target function to be tested does not exceed the scoring threshold, the target function to be tested is tested using the test case extraction ratio determined according to the serial number of the target function to be tested in the target sorting, and the test case is selected from the full test case set of the target function to be tested.

[0105] In this application, considering that the index value of a function in a code file under a complexity evaluation index can reflect the complexity of the function, and the complexity of the function also directly affects the probability of problems occurring in the function during the operation of the function, based on this principle, in the application, the risk score of the function is determined by the index value of each function under m complexity evaluation indicators. The higher the risk score of the function, the higher the probability of problems occurring during the operation of the function. Moreover, m is greater than 1. The risk score of the function is determined by the index values ​​under multiple different complexity evaluation indicators of the function, which can ensure the accuracy of the determined risk score. Afterwards, multiple functions in the code file to be tested are sorted in descending order according to the risk scores to obtain the target sorting; and multiple functions in the code file to be tested are tested according to the target sorting. In this way, it can be ensured that the functions with higher risk scores are tested first, that is, high-risk functions are tested first. In this way, problems of functions with higher risks will be exposed first during the testing process. Moreover, the number of problems exposed by functions with higher risks is usually larger. In the process of testing other subsequent functions, developers can simultaneously troubleshoot and fix problems exposed by the functions tested first. The time for subsequent testing of other functions also ensures that developers have enough time to troubleshoot and fix problems in the functions tested first. In this way, the extension of the software development cycle due to unreasonable code testing order can be effectively avoided. While ensuring testing efficiency, the overall software development efficiency can be improved.

[0106] The solution of this application is described below with reference to a specific embodiment. Figure 5 is a flow chart of a testing method according to an embodiment of the present application, as shown in FIG. Figure 5 Shown, including:

[0107] Step 510: Obtain the index value of each function in the code file to be tested under four complexity evaluation indexes.

[0108] Assuming that the code file to be tested is a C language code file to be tested, the index values ​​of each function in the C language code file to be tested under four complexity evaluation indicators can be counted, that is, the cyclomatic complexity, number of function parameters, number of return statements, and function nesting depth of each function are counted. In this embodiment, assuming that the C language code file to be tested includes five functions, the five functions and the index values ​​of each function under the four complexity evaluation indicators are shown in Table 1 below:

[0109]

[0110] Table 1

[0111] Step 520: construct an indicator matrix and standardize the indicator matrix to obtain a standardized indicator matrix;

[0112] Based on the index values ​​of the above five functions under the four complexity evaluation indicators shown in Table 1, the following index matrix can be constructed:

[0113]

[0114] Standardize the indicator matrix X to obtain the standardized indicator matrix Y:

[0115]

[0116] Step 530, calculating the probability of each standardized value under the corresponding complexity evaluation index according to the standardized index matrix, and constructing a probability matrix;

[0117] The probability of each standardized value under the corresponding complexity evaluation index can be calculated according to the above formula 4. The probability of the standardized index value in the i-th row and j-th column of the standardized index matrix Y under the corresponding complexity evaluation index is the element in the i-th row and j-th column of the probability matrix.

[0118] The resulting probability matrix P is as follows:

[0119]

[0120] Step 540 : Calculate the weight of each complexity evaluation index according to the probability of each standardized value under the corresponding complexity evaluation index and the standardized index matrix.

[0121] The information entropy of each complexity evaluation index can be calculated according to the above formula 6, wherein the information entropy of the four complexity evaluation indicators is calculated as follows:

[0122] e1=0.968; e2=0.963; e3=0.7734; e4=0.8499;

[0123] Among them, e1 is the information entropy of cyclomatic complexity; e2 is the information entropy of the number of function parameters; e3 is the information entropy of the number of return statements; and e4 is the information entropy of the function nesting depth.

[0124] According to the above formula 7, we can calculate the utility value U1 of cyclomatic complexity, the utility value U2 of the number of function parameters, the utility value U3 of the number of return statements, and the utility value U4 of the function nesting depth. The calculation results are as follows:

[0125] U1=0.032; U2=0.034; U3=0.2266; U4=0.145;

[0126] According to Formula 8 above, we can calculate the weight W1 of cyclomatic complexity, the weight W2 of the number of function parameters, the weight W3 of the number of return statements, and the weight W4 of the function nesting depth. The calculation results are as follows:

[0127] W1=0.0731; W2=0.0777; W3=0.5178; W4=0.3313;

[0128] Step 550 : Calculate the maximum index distance and the minimum index distance of each function according to the weight of each complexity evaluation index and the standardized index matrix.

[0129] According to Formula 9 above, the maximum standardized value of cyclomatic complexity can be determined based on the standardized indicator matrix. The maximum normalized value for the number of function parameters Returns the maximum normalized value of the number of statements The maximum normalized value of function nesting depth Here are the results:

[0130]

[0131] According to the above formula 10, the minimum standardized value of cyclomatic complexity can be determined based on the labeled standardized indicator matrix Minimum normalized value for the number of function parameters Returns the minimum normalized value of the number of statements Minimum normalized value of function nesting depth Here are the results:

[0132]

[0133] According to the above formula 11, the maximum index distance of the above five functions can be calculated, and the results are as follows:

[0134]

[0135] in, is the maximum index distance of the function whose sequence number is 1. is the maximum index distance of the function with function number 2; the same applies to the others.

[0136] According to the above formula 12, the minimum index distance of the above five functions can be calculated, and the results are as follows:

[0137]

[0138] in, is the maximum index distance of the function whose sequence number is 1. is the maximum index distance of the function with function number 2; the same applies to the others.

[0139] Step 560 : Determine the risk score of each function based on the maximum indicator distance and the minimum indicator distance of each function.

[0140] According to the above formula 13, the risk scores of the above five functions can be calculated, and the results are as follows:

[0141] S1=0.1491; S2=0.4520, S3=0.3; S4=0.3214; S5=0.294;

[0142] Among them, S1 is the risk score of the function with the function number 1, and S2 is the risk score of the function with the function number 2; the same applies to the others.

[0143] Step 570 , sorting the multiple functions in the code file to be tested in descending order of risk scores to obtain a target sorting, and testing the multiple functions in the code file to be tested according to the target sorting.

[0144] Sort the five functions in the code file to be tested by risk score from high to low. After obtaining the target ranking, the function's test number is the function's number in the target ranking. Based on the risk score of each function, the test number of each function can be obtained as shown in Table 2 below:

[0145] Function number function Risk Score Test serial number 1 SCM_Diag_SeatMotPositionLearnReques 0.1491 5 2 SCM_MotorNegativeOperation 0.4520 1 3 SCM_SeatMotorPositionLearnHandler 0.3 3 4 SCM_MotorFaultTypeGet 0.3214 2 5 SCM_MotorRecallOperation 0.294 4

[0146] Table 2

[0147] As can be seen from Table 2, the order of risk scores from high to low is: function with function number 2 → function with function number 4 → function with function number 3 → function with function number 5 → function with function number 1.

[0148] Correspondingly, the order of test numbers from high to low is: function with function number 2 → function with function number 4 → function with function number 3 → function with function number 5 → function with function number 1.

[0149] White-box testing was performed on the five functions in sequence according to the determined test sequence. The number of problems exposed during the white-box testing of the five functions was counted. The statistical results are shown in Table 3 below:

[0150]

[0151] Table 3

[0152] As shown in Table 3, the five functions are sorted from highest to lowest by the number of issues encountered: function number 2 → function number 3 → function numbers 4 and 5 → function number 1. Combined with the aforementioned order of test numbers from high to low, it can be seen that the number of issues exposed during testing is negatively correlated with the test number determined by the function's risk score. That is, the higher the risk score, the earlier the function is tested (i.e., the lower the test number), and the more issues are exposed during testing.

[0153] Therefore, through the solution of this application, without affecting the test efficiency, problems of high-risk functions can be exposed first during the testing process, leaving developers with sufficient time to confirm and fix the problems, thereby improving the overall software development efficiency.

[0154] The following describes an embodiment of the device of the present application, which can be used to perform the method described in the above embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the above method embodiment of the present application.

[0155] Figure 6 is a block diagram of a testing device according to an embodiment of the present application. Figure 6 As shown, the testing device includes: an indicator value acquisition module 610, which is used to obtain the indicator value of each function in the code file to be tested under m complexity evaluation indicators, where m is a positive integer greater than 1; a score determination module 620, which is used to determine the risk score of each function according to the indicator value of each function in the code file to be tested under m complexity evaluation indicators; a sorting module 630, which is used to sort multiple functions in the code file to be tested in order of risk score from high to low to obtain a target sorting; a testing module 640, which is used to test multiple functions in the code file to be tested according to the target sorting.

[0156] In some embodiments, the score determination module 620 includes: an indicator matrix determination unit, which is used to construct an indicator matrix based on the indicator values ​​of each function in the code file to be tested under m complexity evaluation indicators; a standardization unit, which is used to standardize the indicator matrix to obtain a standardized indicator matrix, and the standardized indicator matrix includes the standardized values ​​after standardization of each indicator value; an indicator weight determination unit, which is used to determine the weight of each complexity evaluation indicator based on the standardized indicator matrix; and a risk score determination unit, which is used to determine the risk score of each function based on the weight of each complexity evaluation indicator and the indicator value of each function under m complexity evaluation indicators.

[0157] In some embodiments, the indicator weight determination unit includes: a probability determination unit, which is used to calculate the probability of each standardized value under the corresponding complexity evaluation indicator based on the standardized indicator matrix; an information entropy determination unit, which is used to determine the information entropy of each complexity evaluation indicator based on multiple standardized values ​​under the complexity evaluation indicator; a utility value determination unit, which is used to determine the utility value of each complexity evaluation indicator based on the information entropy of each complexity evaluation indicator; a weight determination unit, which is used to calculate the proportion of the utility value of each complexity evaluation indicator in the total utility value to obtain the weight of each complexity evaluation indicator, and the total utility value is equal to the sum of the utility values ​​of m complexity evaluation indicators.

[0158] In some embodiments, the risk score determination unit includes: a statistical unit for determining the maximum standardized value and the minimum standardized value under each complexity evaluation indicator based on the standardized indicator matrix; a maximum indicator distance determination unit for determining the maximum indicator distance of the function for each function based on the difference between the standardized value of the function under each complexity evaluation indicator and the maximum standardized value under the corresponding complexity evaluation indicator, as well as the weight of the corresponding complexity evaluation indicator; a minimum indicator distance determination unit for determining the minimum indicator distance of the function for each function based on the difference between the standardized value of the function under each complexity evaluation indicator and the minimum standardized value under the corresponding complexity evaluation indicator, as well as the weight of the corresponding complexity evaluation indicator; and a scoring unit for determining the risk score of each function based on the maximum indicator distance and the minimum indicator distance of each function.

[0159] In some embodiments, the maximum index distance determination unit is further used to: perform the following processing on each function: calculate the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index to obtain the first index difference of the function under each complexity evaluation index; calculate the maximum index distance of the function based on the weights of multiple complexity evaluation indicators and the first index difference of the function under multiple complexity evaluation indicators.

[0160] In some embodiments, the minimum index distance determination unit is further used to: perform the following processing on each function: calculate the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index to obtain the second index difference of the function under each complexity evaluation index; calculate the minimum index distance of the function based on the weights of multiple complexity evaluation indicators and the second index difference of the function under multiple complexity evaluation indicators.

[0161] In some embodiments, the scoring unit is further used to: for each function, divide the minimum indicator distance of the function by the sum of the indicator distances of the function to obtain a risk score of the function, where the sum of the indicator distances of the function is the sum of the maximum indicator distance and the minimum indicator distance of the function.

[0162] In some embodiments, the m complexity evaluation indicators are at least two of cyclomatic complexity, number of function parameters, number of return statements, and function nesting depth.

[0163] In some embodiments, the testing module 640 is further configured to test multiple functions in the code file to be tested using a test case set of corresponding functions according to target sorting.

[0164] In some embodiments, the testing device also includes: a use case extraction ratio determination module, which is used to determine the use case extraction ratio of each function according to the serial number of each function in the target sorting, and the use case extraction ratio is negatively correlated with the serial number of the corresponding function in the target sorting; a test case set determination module, which is used to select test cases from the full test case set of the corresponding function according to the use case extraction ratio of each function, and add them to the test case set of the corresponding function.

[0165] Figure 7 FIG. 1 is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. The electronic device can be used to execute the test method provided by the present application. Figure 7 As shown, the electronic device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and optionally, the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may optionally also be a storage device independent of the aforementioned processor 1001. Those skilled in the art will understand that, Figure 7 The structure of the electronic device shown in the figure does not constitute a limitation of the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0166] like Figure 7 As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a program for implementing the test method. Figure 7 In the electronic device shown, the network interface 1004 is primarily used for communicating with other devices. The user interface 1003 is primarily used for connecting to a client (user end) and communicating data with the client. The processor 1001 can be used to call a program implementing a test method stored in the memory 1005 and execute the steps of the test method in any of the above method embodiments.

[0167] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the testing method in any of the above method embodiments is implemented.

[0168] According to one aspect of an embodiment of the present application, a computer program product is provided, which includes computer instructions. When the computer instructions are executed by a processor, the testing method in any of the above method embodiments is implemented.

[0169] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.

[0170] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.

[0171] Those skilled in the art will readily conceive of other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of this application and include common knowledge or customary techniques in the art that are not disclosed herein.

[0172] It should be understood that the present application is not limited to the exact structure described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A testing method, characterized in that: include: Obtain the index value of each function in the code file to be tested under m complexity evaluation indicators, where m is a positive integer greater than 1; Determine the risk score of each function according to the index value of each function in the code file to be tested under the m complexity evaluation indexes; Sorting multiple functions in the code file to be tested in descending order of risk scores to obtain a target sorting; According to the target sorting, multiple functions in the code file to be tested are tested.

2. The method according to claim 1, characterized in that Determining the risk score of each function according to the index value of each function in the code file to be tested under the m complexity evaluation indexes includes: Constructing an indicator matrix according to the indicator values ​​of each function in the code file to be tested under m complexity evaluation indicators; Standardizing the indicator matrix to obtain a standardized indicator matrix, wherein the standardized indicator matrix includes standardized values ​​obtained by standardizing each of the indicator values; Determining the weight of each complexity evaluation indicator according to the standardized indicator matrix; The risk score of each of the functions is determined according to the weight of each of the complexity evaluation indicators and the indicator value of each of the functions under the m complexity evaluation indicators.

3. The method according to claim 2, characterized in that Determining the weight of each complexity evaluation indicator according to the standardized indicator matrix includes: According to the standardized indicator matrix, the probability of each standardized value under the corresponding complexity evaluation indicator is calculated; For each complexity evaluation indicator, determining the information entropy of each complexity evaluation indicator according to a plurality of standardized values ​​under the complexity evaluation indicator; Determining the utility value of each complexity evaluation indicator according to the information entropy of each complexity evaluation indicator; The proportion of the utility value of each complexity evaluation index in the total utility value is calculated to obtain the weight of each complexity evaluation index, and the total utility value is equal to the sum of the utility values ​​of the m complexity evaluation indicators.

4. The method according to claim 2, characterized in that: Determining the risk score of each function according to the weight of each complexity evaluation index and the index value of each function under the m complexity evaluation indexes includes: According to the standardized indicator matrix, determining the maximum standardized value and the minimum standardized value under each of the complexity evaluation indicators; For each function, according to the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index, and the weight of the corresponding complexity evaluation index, determine the maximum index distance of the function; For each function, according to the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index, and the weight of the corresponding complexity evaluation index, determine the minimum index distance of the function; The risk score of each of the functions is determined according to the maximum indicator distance and the minimum indicator distance of each of the functions.

5. The method according to claim 4, characterized in that The step of determining the maximum index distance of each function according to the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index, and the weight of the corresponding complexity evaluation index, comprises: Perform the following processing for each function: Calculate the difference between the normalized value of the function under each complexity evaluation index and the maximum normalized value under the corresponding complexity evaluation index to obtain the first index difference of the function under each complexity evaluation index; The maximum indicator distance of the function is calculated according to the weights of the plurality of complexity evaluation indicators and the first indicator difference of the function under the plurality of complexity evaluation indicators.

6. The method according to claim 4, characterized in that The step of determining the minimum index distance of each function according to the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index, and the weight of the corresponding complexity evaluation index, comprises: Perform the following processing for each function: Calculate the difference between the normalized value of the function under each complexity evaluation index and the minimum normalized value under the corresponding complexity evaluation index to obtain a second index difference of the function under each complexity evaluation index; The minimum indicator distance of the function is calculated according to the weights of the plurality of complexity evaluation indicators and the second indicator differences of the function under the plurality of complexity evaluation indicators.

7. The method according to claim 4, characterized in that Determining the risk score of each function according to the maximum indicator distance and the minimum indicator distance of each function includes: For each function, the minimum indicator distance of the function is divided by the sum of the indicator distances of the function to obtain the risk score of the function, where the sum of the indicator distances of the function is the sum of the maximum indicator distance and the minimum indicator distance of the function.

8. The method according to any one of claims 1 to 7, characterized in that The m complexity evaluation indicators are at least two of cyclomatic complexity, the number of function parameters, the number of return statements and function nesting depth.

9. The method according to any one of claims 1 to 7, characterized in that The testing of multiple functions in the code file to be tested according to the target sorting includes: According to the target sorting, multiple functions in the code file to be tested are tested using the test case set of the corresponding function.

10. The method according to claim 9, characterized in that Before testing the multiple functions in the code file to be tested by using the test case set of the corresponding function according to the target sorting, the method further includes: According to the sequence number of each function in the target ranking, determining the use case extraction ratio of each function, wherein the use case extraction ratio is negatively correlated with the sequence number of the corresponding function in the target ranking; According to the use case extraction ratio of each of the functions, test cases are selected from the full test case set of the corresponding function and added to the test case set of the corresponding function.

11. A testing device, characterized in that: include: An index value acquisition module is used to obtain the index value of each function in the code file to be tested under m complexity evaluation indicators, where m is a positive integer greater than 1; A scoring determination module, used to determine the risk score of each function in the code file to be tested according to the index value of each function under m complexity evaluation indexes; A sorting module is used to sort the multiple functions in the code file to be tested in descending order of risk scores to obtain a target sorting; The test module is used to test multiple functions in the code file to be tested according to the target sorting.

12. An electronic device, characterized in that: include: processor; A memory, wherein computer instructions are stored in the memory, and when the computer instructions are executed by the processor, the method according to any one of claims 1 to 10 is implemented.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 10 is implemented.