Conditional Branch Coverage Calculation Excluding Unnecessary Code
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Current code coverage testing methods provide inaccurate and unreliable results due to the inability to accurately calculate conditional branch coverage, especially in sophisticated projects where some conditional branches are unnecessary or impossible to cover.
Innovation Solution
A method and device for calculating conditional branch coverage by acquiring code types and comment information of uncovered conditional branch code lines, determining coverage parameters based on this information, and calculating coverage by adding these parameters to the total number of conditional branch code lines, thereby excluding unnecessary branches from the calculation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If traditional code coverage testing is performed including all conditional branches, then the testing process is comprehensive, but the coverage results become inaccurate and unreliable due to unnecessary or impossible-to-cover branches
Solution Approach 1:
The patent extracts and excludes unnecessary conditional branches from the coverage calculation. By identifying branches that are impossible to cover or unnecessary for testing purposes, the system removes them from the denominator in coverage calculations, thereby improving both accuracy and reliability of coverage reports
Solution Approach 2:
The patent applies different treatment to different conditional branches based on their specific characteristics. Some branches are marked as unnecessary or impossible to cover, and these receive special handling in the coverage calculation, allowing localized adjustments to improve overall measurement quality
2Manufacturing precision
If all conditional branches are required to be covered, then the testing standard is strict and thorough, but the testing requirements cannot be met for sophisticated projects with unnecessary or impossible branches
Solution Approach 1:
The patent introduces dynamic adaptability to testing standards by allowing the coverage requirements to adjust based on the specific characteristics of the codebase. Necessary branches maintain strict coverage requirements, while unnecessary or impossible branches are dynamically excluded, making the testing standard adaptable to different project scenarios
Solution Approach 2:
The patent changes the parameters of coverage calculation by introducing weights and exclusion flags for different conditional branches. This allows the testing standard to be flexible - maintaining high precision for important branches while adapting to exclude problematic branches, thus balancing strictness and adaptability
Data Source
AI summary
The present disclosure relates to a conditional branch coverage calculation method and device, computer apparatus, storage medium and computer program product. The method includes: acquiring code types of uncovered conditional branch code lines in target code, and acquiring comment information corresponding to the uncovered conditional branch code lines according to the code type; acquiring coverage parameter corresponding to the uncovered conditional branch code lines according to the comment information corresponding to the uncovered conditional branch code lines; and calculating a conditional branch coverage corresponding to the target code according to the coverage parameters corresponding to the uncovered conditional branch code lines and a total number of conditional branch code lines in the target code.

