A method and system for generating MC / DC test case set during short-circuit evaluation

By generating a test case set that meets the MC/DC test coverage criteria and judging the short-circuit evaluation of code fragments, the challenges caused by short-circuit evaluation in software testing are solved and testing efficiency is improved.

CN118227509BActive Publication Date: 2024-09-17CHINA STATE SHIPBUILDING CORP LTD RESEARCH INSTITUTE 719
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410620867.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-20
Publication Date
2024-09-17
Estimated Expiration
2044-05-20

AI Technical Summary

Technical Problem

In software testing, the short-circuit evaluation phenomenon brings challenges to MC/DC testing, making it difficult to ensure that all decisions and conditions of the program are fully covered.

Method used

By obtaining the value of the conditional expression from the existing test case set, an initial test case set is generated according to the MC/DC test coverage criteria, and new test cases are generated based on the coverage situation and decision path, and a code fragment short-circuit evaluation judgment model is set. Calculate the short-circuit evaluation judgment index to determine whether there is a short-circuit evaluation in the code fragment, so as to select an appropriate test case set for testing.

Benefits of technology

Generating test case sets that meet the MC/DC test coverage criteria improves the efficiency of software testing. It can effectively determine the possibility of short-circuit evaluation in code fragments and select appropriate test case sets, thereby improving testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118227509B
    Figure CN118227509B
Patent Text Reader

Abstract

The invention discloses a method and system for generating an MC / DC test case set during short-circuit evaluation. The method comprises: obtaining values ​​of conditional expressions of multiple test cases from an existing test case set, generating an initial test case set that meets the MC / DC test coverage criterion according to the values ​​of the conditional expressions and the MC / DC test coverage criterion; when there are test cases in the existing test case set that do not meet the MC / DC test coverage criterion, generating new test cases according to the coverage and decision paths of the existing test cases, and adding the new test cases to the initial test case set to generate a final test case set; dividing a code to be tested into multiple code fragments, setting a code fragment short-circuit evaluation judgment model, calculating a short-circuit evaluation judgment index of each code fragment, determining that the corresponding code fragment has a short-circuit evaluation when a judgment threshold is exceeded, testing the code to be tested through the final test case set, otherwise, testing through the existing test case set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of code testing, and more specifically, relates to a method and system for generating an MC / DC test case set during short-circuit evaluation. Background Art

[0002] Software testing is a quality assurance process that aims to evaluate whether a software product meets the expected functional, performance, and security requirements. Testers check various aspects of the software, including functionality, interface, performance, security, etc., by executing a series of test cases. Software testing usually includes the following stages:

[0003] Unit testing: Testing a single module or component in the software to ensure its correct functionality.

[0004] Integration testing: Testing the integration between different modules to ensure that they work together correctly.

[0005] System testing: Testing the entire system to verify whether it meets the functional and performance requirements.

[0006] Acceptance Testing: Final testing performed before software is delivered to the customer to ensure that the software meets the customer's needs and expectations.

[0007] In software testing, MC / DC (Modified Condition / Decision Coverage) is an important test coverage criterion used to ensure that test cases fully cover all decisions and conditions of the program. However, when processing logical expressions, short-circuit evaluation often occurs, which brings challenges to MC / DC testing. Summary of the invention

[0008] In order to solve the above technical problems, the present invention proposes a method for generating an MC / DC test case set during short-circuit evaluation, comprising:

[0009] From the existing test case set, obtain the values ​​of the conditional expressions of multiple test cases, and generate an initial test case set that meets the MC / DC test coverage criteria based on the values ​​of the conditional expressions and the MC / DC test coverage criteria;

[0010] When there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, new test cases are generated according to the coverage and decision paths of the existing test cases, and added to the initial test case set to generate a final test case set;

[0011] The code to be tested is divided into multiple code fragments, a code fragment short-circuit evaluation judgment model is set, and the short-circuit evaluation judgment index of each code fragment is calculated. When the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0012] Furthermore, the code snippet short-circuit evaluation judgment model includes:

[0013] ,

[0014] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of a conditional expression is For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0015] Furthermore, the performance index of the code snippet is calculated. include:

[0016] ,

[0017] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0018] Furthermore, the readability index of the code snippet is calculated include:

[0019] ,

[0020] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0021] Furthermore, based on the coverage and decision paths of existing test cases, generating new test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case.

[0022] Furthermore, when the result meets the MC / DC test coverage criteria, the selected test case is added to the initial test case set as a new test case; when the result does not meet the MC / DC test coverage criteria, the remaining conditional expressions are traversed from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0023] The present invention also provides a system for generating a MC / DC test case set during short-circuit evaluation, comprising:

[0024] The module for obtaining the initial test case set is used to obtain the values ​​of the conditional expressions of multiple test cases from the existing test case set, and generate the initial test case set that meets the MC / DC test coverage criteria according to the values ​​of the conditional expressions and the MC / DC test coverage criteria;

[0025] A module for generating a final test case set is used to generate new test cases according to the coverage and decision paths of the existing test cases when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, and add them to the initial test case set to generate a final test case set;

[0026] The test module is used to divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0027] Furthermore, the code snippet short-circuit evaluation judgment model includes:

[0028] ,

[0029] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0030] Furthermore, the performance index of the code snippet is calculated. include:

[0031] ,

[0032] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0033] Furthermore, the readability index of the code snippet is calculated include:

[0034] ,

[0035] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0036] Furthermore, based on the coverage and decision paths of the existing test cases, generating new test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case; when the result meets the MC / DC test coverage criteria, adding the selected test case as a new test case to the initial test case set; when the result does not meet the MC / DC test coverage criteria, traversing the remaining conditional expressions from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0037] Compared with the prior art, the above technical solution conceived by the present invention has the following beneficial effects:

[0038] Through the above technical scheme, the present invention can generate a test case set that meets the MC / DC test coverage criteria, and first determine the possibility of short-circuit evaluation in each code fragment, so as to select the corresponding test case set, which can improve the efficiency of software testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 is a flow chart of the method of embodiment 1 of the present invention;

[0040] Figure 2 It is a system structure diagram of embodiment 2 of the present invention. DETAILED DESCRIPTION

[0041] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0042] The method provided by the present invention can be implemented in the following terminal environment, and the terminal may include one or more of the following components: a processor, a storage medium, and a display screen. The storage medium stores at least one instruction, and the instruction is loaded and executed by the processor to implement the method described in the following embodiment.

[0043] The processor may include one or more processing cores. The processor uses various interfaces and lines to connect various parts in the entire terminal, and executes various functions of the terminal and processes data by running or executing instructions, programs, code sets or instruction sets stored in the storage medium, and calling data stored in the storage medium.

[0044] The storage medium may include a random access memory (RAM) or a read-only memory (ROM). The storage medium may be used to store instructions, programs, codes, code sets or instructions.

[0045] The display is used to show the interactive cross-section of each application.

[0046] All subscripts in the formulas of the present invention are only used to distinguish parameters and have no actual meaning.

[0047] In addition, those skilled in the art can understand that the structure of the above terminal does not constitute a limitation on the terminal, and the terminal may include more or fewer components, or combine certain components, or arrange the components differently. For example, the terminal also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, and a power supply, which will not be described in detail here.

[0048] Example 1

[0049] like Figure 1As shown, an embodiment of the present invention provides a method for generating an MC / DC test case set during short-circuit evaluation, comprising:

[0050] Step 101, obtaining values ​​of conditional expressions of multiple test cases from an existing test case set, and generating an initial test case set that meets the MC / DC test coverage criterion according to the values ​​of the conditional expressions and the MC / DC test coverage criterion;

[0051] Step 102, when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, new test cases are generated according to the coverage and decision paths of the existing test cases, and added to the initial test case set to generate a final test case set;

[0052] Specifically, generating a new test case according to the coverage and decision path of the existing test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case; when the result meets the MC / DC test coverage criteria, adding the selected test case as a new test case to the initial test case set; when the result does not meet the MC / DC test coverage criteria, traversing the remaining conditional expressions from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0053] As shown in Table 1, for example, for the expression , when there are use cases a=1, b=1, c=1, d=1, due to the short-circuit evaluation, a use case set of a, b, c, d that does not meet the MC / DC standard is obtained:

[0054] ,

[0055] As shown in Table 2, for use case 1, changing the value of c results in the following use cases:

[0056] ,

[0057] As shown in Table 3, at this time, d becomes a non-short circuit condition, and together with case 1, condition c satisfies the MC / DC standard, and is added to the test set:

[0058] ,

[0059] As shown in Table 4, since a, b, and d are not satisfied, for use case 2, the value of d is changed to obtain the following use case:

[0060] ,

[0061] As shown in Table 5, at this time, condition d meets the MC / DC standard together with case 2, and is added to the test set:

[0062] ,

[0063] As shown in Table 6, since a and b are not satisfied and b is short-circuited in use case 3, for use case 3, the value of a is changed to obtain the use case:

[0064] ,

[0065] As shown in Table 7, at this time, b becomes a non-short circuit condition, c and d are short circuited, and together with case 3, a satisfies the MC / DC standard, and is added to the test set:

[0066] ,

[0067] As shown in Table 8, since b is not satisfied, for use case 4, the value of b is changed to obtain the use case:

[0068] ,

[0069] As shown in Table 9, at this time, any use case in the existing use case set cannot make condition b meet the MC / DC standard, and the value of d is changed:

[0070] ,

[0071] As shown in Table 10, at this time, condition b meets the MC / DC standard together with case 4, and is added to the test set:

[0072] ,

[0073] At this point, this use case set satisfies MC / DC.

[0074] Step 103, divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0075] Specifically, the code snippet short-circuit evaluation judgment model includes:

[0076] ,

[0077] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0078] Specifically, calculate the performance index of the code snippet include:

[0079] ,

[0080] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0081] Specifically, calculate the readability index of the code snippet include:

[0082] ,

[0083] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0084] Example 2

[0085] like Figure 2 As shown, an embodiment of the present invention further provides a system for generating an MC / DC test case set during short-circuit evaluation, comprising:

[0086] The module for obtaining the initial test case set is used to obtain the values ​​of the conditional expressions of multiple test cases from the existing test case set, and generate the initial test case set that meets the MC / DC test coverage criteria according to the values ​​of the conditional expressions and the MC / DC test coverage criteria;

[0087] A module for generating a final test case set is used to generate new test cases according to the coverage and decision paths of the existing test cases when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, and add them to the initial test case set to generate a final test case set;

[0088] Specifically, generating a new test case according to the coverage and decision path of the existing test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case; when the result meets the MC / DC test coverage criteria, adding the selected test case as a new test case to the initial test case set; when the result does not meet the MC / DC test coverage criteria, traversing the remaining conditional expressions from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0089] The test module is used to divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0090] Specifically, the code snippet short-circuit evaluation judgment model includes:

[0091] ,

[0092] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0093] Specifically, calculate the performance index of the code snippet include:

[0094] ,

[0095] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0096] Specifically, calculate the readability index of the code snippet include:

[0097] ,

[0098] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0099] Example 3

[0100] The embodiment of the present invention further provides a storage medium storing a plurality of instructions, wherein the instructions are used to implement the method for generating an MC / DC test case set during short-circuit evaluation.

[0101] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.

[0102] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: Step 101, obtaining values ​​of conditional expressions of multiple test cases from an existing test case set, and generating an initial test case set that meets the MC / DC test coverage criterion according to the values ​​of the conditional expressions and the MC / DC test coverage criterion;

[0103] Step 102, when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, new test cases are generated according to the coverage and decision paths of the existing test cases, and added to the initial test case set to generate a final test case set;

[0104] Specifically, generating a new test case according to the coverage and decision path of the existing test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case; when the result meets the MC / DC test coverage criteria, adding the selected test case as a new test case to the initial test case set; when the result does not meet the MC / DC test coverage criteria, traversing the remaining conditional expressions from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0105] Step 103, divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0106] Specifically, the code snippet short-circuit evaluation judgment model includes:

[0107] ,

[0108] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression is The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0109] Specifically, calculate the performance index of the code snippet include:

[0110] ,

[0111] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0112] Specifically, calculate the readability index of the code snippet include:

[0113] ,

[0114] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0115] Example 4

[0116] An embodiment of the present invention also proposes an electronic device, including a processor and a storage medium connected to the processor, wherein the storage medium stores multiple instructions, which can be loaded and executed by the processor to enable the processor to execute a method for generating an MC / DC test case set during short-circuit evaluation.

[0117] Specifically, the electronic device of this embodiment may be a computer terminal, and the computer terminal may include: one or more processors, and a storage medium.

[0118] Wherein, the storage medium can be used to store software programs and modules, such as a method for generating a MC / DC test case set during short-circuit evaluation in an embodiment of the present invention, corresponding program instructions / modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the storage medium, that is, realizing the above-mentioned method for generating a MC / DC test case set during short-circuit evaluation. The storage medium may include a high-speed random storage medium, and may also include a non-volatile storage medium, such as one or more magnetic storage systems, flash memory, or other non-volatile solid-state storage media. In some instances, the storage medium may further include a storage medium remotely arranged relative to the processor, and these remote storage media may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0119] The processor may call the information and application program stored in the storage medium through the transmission system to execute the steps: Step 101, obtaining values ​​of conditional expressions of multiple test cases from an existing test case set, and generating an initial test case set that meets the MC / DC test coverage criterion according to the values ​​of the conditional expressions and the MC / DC test coverage criterion;

[0120] Step 102, when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, new test cases are generated according to the coverage and decision paths of the existing test cases, and added to the initial test case set to generate a final test case set;

[0121] Specifically, generating a new test case according to the coverage and decision path of the existing test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case; when the result meets the MC / DC test coverage criteria, adding the selected test case as a new test case to the initial test case set; when the result does not meet the MC / DC test coverage criteria, traversing the remaining conditional expressions from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

[0122] Step 103, divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, it is tested through the existing test case set.

[0123] Specifically, the code snippet short-circuit evaluation judgment model includes:

[0124] ,

[0125] in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The depth of function calls in the right-hand side expression of a conditional expression.

[0126] Specifically, calculate the performance index of the code snippet include:

[0127] ,

[0128] in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet.

[0129] Specifically, calculate the readability index of the code snippet include:

[0130] ,

[0131] in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

[0132] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0133] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0134] In the several embodiments provided by the present invention, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the system embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0135] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0136] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0137] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only storage medium (ROM, Read-Only Memory), random access storage medium (RAM, RandomAccess Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.

[0138] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the invention.

Claims

1. A method for generating MC / DC test case sets during short-circuit evaluation, It is characterized in that include: From the existing test case set, obtain the values ​​of the conditional expressions of multiple test cases, and generate an initial test case set that meets the MC / DC test coverage criteria based on the values ​​of the conditional expressions and the MC / DC test coverage criteria; When there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, new test cases are generated according to the coverage and decision paths of the existing test cases, and added to the initial test case set to generate a final test case set; Divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when it exceeds the judgment threshold, determine that the corresponding code fragment has a short-circuit evaluation situation, then test the code to be tested through the final test case set, otherwise, test it through the existing test case set; The code snippet short-circuit evaluation judgment model includes: , in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The function call depth in the right-hand side expression of the conditional expression, is the performance index of the code snippet, is the readability index of the code snippet; Calculate the performance index of a code snippet include: , in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet; Calculate the readability index of a code snippet include: , in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

2. A method for generating a MC / DC test case set during short-circuit evaluation as claimed in claim 1, It is characterized in that Then, according to the coverage and decision path of the existing test cases, generating new test cases includes: selecting a test case from the existing test cases, selecting a conditional expression that does not meet the MC / DC test coverage criteria in the selected test cases, changing the value of the selected conditional expression from back to front, and calculating the result of the short-circuit evaluation of the selected test case.

3. A method for generating a MC / DC test case set during short-circuit evaluation as claimed in claim 2, It is characterized in that When the result meets the MC / DC test coverage criteria, the selected test case is added to the initial test case set as a new test case. When the result does not meet the MC / DC test coverage criteria, the remaining conditional expressions are traversed from back to front to find the value of the selected conditional expression that can meet the MC / DC test coverage criteria.

4. A system for generating MC / DC test case sets during short-circuit evaluation, It is characterized in that include: The module for obtaining the initial test case set is used to obtain the values ​​of the conditional expressions of multiple test cases from the existing test case set, and generate the initial test case set that meets the MC / DC test coverage criteria according to the values ​​of the conditional expressions and the MC / DC test coverage criteria; A module for generating a final test case set is used to generate new test cases according to the coverage and decision paths of the existing test cases when there are test cases in the existing test case set that do not meet the MC / DC test coverage criteria, and add them to the initial test case set to generate a final test case set; A test module is used to divide the code to be tested into multiple code fragments, set a code fragment short-circuit evaluation judgment model, calculate the short-circuit evaluation judgment index of each code fragment, and when the judgment threshold is exceeded, it is determined that the corresponding code fragment has a short-circuit evaluation situation, and the code to be tested is tested through the final test case set, otherwise, the code is tested through the existing test case set; The code snippet short-circuit evaluation judgment model includes: , in, To short-circuit the evaluation index, is the number of conditional expressions, For the The length of the left-hand side expression of the conditional expression, For the The total length of the conditional expressions, For the The number of nesting levels of the logical structure where the conditional expression is located, For the The number of variables in the conditional expression, For the The complexity of the right-hand side expression of the conditional expression, For the The number of variables in the left-hand side of the conditional expression, For the The number of operators on the left side of the conditional expression, For the code snippet The number of variables in the entire code snippet involved in the conditional expression, For the code snippet The number of recursive levels in the left-hand side of the conditional expression, For the The function call depth in the right-hand side expression of the conditional expression, is the performance index of the code snippet, is the readability index of the code snippet; Calculate the performance index of a code snippet include: , in, is the performance index of the code snippet, is the number of variables in the entire code snippet involved in the conditional expression in the code snippet, is the total number of lines in the code snippet, is the number of repetitions of the code snippet in the code snippet, is the depth of the deepest nested structure in the code snippet, is the code change between code snippet versions, is the number of conditional branches in the code snippet; Calculate the readability index of a code snippet include: , in, is the readability index of the code snippet, is the number of code snippets, For the The performance index of the code snippet, is the total number of lines of comments in the code snippet, For the code snippet The number of lines of line comments, is the number of long lines in the code snippet, where the number of long lines is the number of code lines that exceed the character count threshold. is the average indentation depth in the code snippet.

5. An electronic device, comprising a processor and a storage medium connected to the processor, wherein the storage medium stores a plurality of instructions, and the instructions can be loaded and executed by the processor so that the processor can execute a method for generating an MC / DC test case set during short-circuit evaluation as claimed in any one of claims 1 to 3.