What settings should be done when statement coverage is required?

8 次查看(过去 30 天)
Hello!
Could you please clarify the following for me?
I am not sure 100% which option is better to check for the coverage analysis. STATEMENT coverage is required in the project.
If I understood corectly, statement coverage is included in CC(Condition coverage) and MCDC (Modified Condition/Decision Coverage) since statement coverage verifies if the conditions were reached.
Thanks for your support!

采纳的回答

Vaibhav
Vaibhav 2024-2-6
Hi Diana
Statement coverage is a subset of both CC (condition coverage) and MCDC (modified condition/decision coverage), ensuring its inclusion in both. Achieving either CC or MCDC automatically guarantees statement coverage. However, there are key differences between these criteria to consider when selecting the appropriate coverage for your project.
Statement coverage:
  • Statement coverage ensures each line of code is executed at least once, serving as the simplest form of coverage analysis.
  • However, it may overlook testing various conditions and decisions within the code, potentially leading to incomplete test coverage.
Condition coverage (CC):
  • Condition coverage necessitates testing each condition in the code to evaluate both its true and false outcomes, ensuring the exploration of different branches.
  • However, it may not mandate testing all possible combinations of conditions, potentially leaving some paths untested, especially in complex decisions with multiple conditions.
Modified condition/decision coverage (MCDC):
  • MCDC (modified condition/decision coverage) is the most stringent criterion, requiring testing of each condition in both its true and false states and every combination of conditions in each decision.
  • It ensures thorough testing of code branches and their interactions, making it highly effective in catching logic errors, but it can be time-consuming and costly to implement.
In summary:
  • If you are only concerned with ensuring that every line of code is executed at least once, then statement coverage is sufficient.
  • If you want to make sure that you are testing all the different branches of your code, then CC is a good option.
  • If you need the most thorough testing possible and are willing to invest the time and resources, then MCDC is the best choice.
Hope this helps!

更多回答(1 个)

Jeremy
Jeremy 2024-3-12
In the Simulink Configuration Parameters, on the Coverage pane, you can set "Structural Coverage Level" to "Block Execution." When you run software-in-the-loop simulation, you will get statement coverage. But also, each metric down the list is inclusive of those before it. So if you set "Structural Coverage Level" to "Decision," you still get statement coverage.
All that to say, I don't think it's even possible to turn statement coverage off unless you completely disable coverage analysis (e.g. by clearing "Enable Coverage Analysis" check box). I hope that helps.
-Jeremy

类别

Help CenterFile Exchange 中查找有关 Test Execution 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by