Coverage report from unit tests is inaccurate

Using the matlab.unittest.plugins.CodeCoveragePlugin with class-based unit tests produces coverage reports that are not always accurate. I see them repeatedly (but not always) occur when function handles are split across multiple lines. The following image provides an example (code to reproduce it is attached).
The "missed line" goes away if you replace isequal(x) with x == x in line 4. Also, if you just remove the ellipsis and have the function handle defined entirely on one line, the report does not display a "missed line."

Réponses (1)

Hello Micah,
Thank you for reporting this. We've had a few other users reporting about this issue and we are working on addressing it.
One possible solution we're looking at is to report code coverage on entire MATLAB statements as opposed to lines. That would ensure that a statement like this -
function_handle_with_wrapping_line_for_isequal = @(x) ~isequal(x, x) || ...
isequal(x, x);
would either be marked as covered or not covered in entirety.
Is that something that you would find useful?
Regards,
Neeraj

4 commentaires

Micah Fry
Micah Fry le 17 Juin 2021
My main concern is seeing a reported "lack of coverage" when there isn't one. That messes with the code coverage metrics as well. Whether the report is by statement or by line, as long as I'm not seeing erroneous red lines (and getting lower coverage percentages), my issue is resolved.
The example was purposefully made to illustrate that the execution MUST be going through the last line (even though it reports that the line wasn't touched). So if the MATLAB's reporting plugin continues to focus on lines rather than statements, a fix would need to show 100% coverage of the example I provided.
Thank you for your feedback, Micah.
Micah Fry
Micah Fry le 17 Juin 2021
Is there a bug tag I can keep track of for this issue? It looks like this may be related to another question (https://www.mathworks.com/matlabcentral/answers/575389-some-lines-missed-in-code-coverage-report).
Micah Fry
Micah Fry le 18 Mar 2022
I see with R2022a this issue is fixed! Thanks @Neeraj Badamikar!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Collect Decision, Condition, and MC/DC Coverage for MATLAB Code dans Centre d'aide et File Exchange

Produits

Version

R2020b

Question posée :

le 16 Juin 2021

Commenté :

le 18 Mar 2022

Community Treasure Hunt

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

Start Hunting!

Translated by