How to exclude certain lines by regex in runsettings file

Haowen Liu 0 Reputation points
2023-02-10T03:59:55.8033333+00:00

I have many asserts scattered around the codebase to check for invalid situations. I want to exclude them in code coverage reports but I have not figured out how to do so. In gcovr I can do something like --exclude-lines-by-pattern '.*assert.*'.

It would be nice if runsettings support something like:

<Lines>
  <Exclude>
    <Line>.*assert.*</Line>
  </Exclude>
</Lines>
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
337 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 29,351 Reputation points Microsoft Vendor
    2023-02-10T08:14:56.79+00:00

    Hello @Haowen Liu ,

    Welcome to Microsoft Q&A forum.

    The .runsettings file doesn’t support excluding one specific line in code coverage. This document: Include or exclude assemblies and members lists what you can exclude in a .runsettings file, by using XML elements and regular expressions.

    But the functions/methods can be excluded in code coverage. There are two ways: one is using <Exclude> and <Function> elements, the other is using ExcludeFromCodeCoverage attribute. Perhaps you can consider writing the specific lines to one function and exclude this function.

    Besides, I recommend submitting a suggestion ticket on our Developer Community for this feature.

    Happy coding.

    Best Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments