Search Unity

Question [ExcludeFromCoverage] in different assemblies

Discussion in 'Testing & Automation' started by TinyMuffin, Feb 16, 2022.

  1. TinyMuffin

    TinyMuffin

    Joined:
    Dec 31, 2018
    Posts:
    6
    Is it possible to use the [ExcludeFromCoverage] attribute in different assemblies? In my project it only works for the predefined 'Assembly-CSharp' assembly. I can't figure out how to make it work in the other assemblies I defined.
     
  2. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    53
    ExcludeFromCodeCoverageAttribute
    in
    System.Diagnostics.CodeAnalysis
    works for me, at least. Not sure if there might be something different with the Unity version.

    If that doesn't work for you, could you give a concrete example of how it's not working?
     
  3. TinyMuffin

    TinyMuffin

    Joined:
    Dec 31, 2018
    Posts:
    6
    I already tried
    ExcludeFromCodeCoverageAttribute
    in
    System.Diagnostics.CodeAnalysis
    . Im using Unity 2019.4 and CodeCoverage 1.1.

    Don't know if it makes sense to give an example since it is so simple. I just have a class where I add the attribute.

    Code (CSharp):
    1. [ExcludeFromCoverage]
    2. public class MyClass {...}
    Like I already mentioned, if I do the same on a class in the predefined assembly it works. The 'Exclude path/file from coverage' option also doesn't work for me... even for paths/files in the predefined assembly.
     
  4. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    53
    I'm using those exact same versions in one of my open source projects. You can see this working here and also this file is not included here.

    If none of the options are working, are you sure you are actually regenerating the coverage, or perhaps looking at old results? Otherwise this is probably some intricate difference in your project setup which is causing issues.
     
  5. TinyMuffin

    TinyMuffin

    Joined:
    Dec 31, 2018
    Posts:
    6
    Thanks for the reply. I have retested it. Not working.

    Additional information about my setup:
    • [ExcludeFromCodeCoverage] applied on internal class
    • Using Entities package 'Version 0.11.2-preview.1 - September 17, 2020
    • Burst Compilation is not disabled because I don't care at the moment if the code coverage "is accurate or not"
    • No included or excluded paths selected
    • I can confirm that I see the latest results as I see the [ExcludeFromCodeCoverage] attribute when I inspect the code line in the file which should not be covered
    • The assembly I defined targets "Any Platform"
    • The assembly I defined has following assembly definition references "Unity.Collections, Unity.Mathematics and Unity.TextMeshPro"
    • The assembly I defined has in the "General" group "Auto Referenced" ticked.
     
  6. JuliusJ

    JuliusJ

    QA Minion of the month Unity Technologies

    Joined:
    May 20, 2015
    Posts:
    35
    Could you submit a bug report with either a small repro project which could show the issue or with your full project? I've tried recreating the issue using information you've provided here but couldn't get it to happen.
     
  7. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi @TinyMuffin - have you got any updates on this? Do you still have this issue?