Search Unity

Resolved Prevent Code Coverage from opening Explorer *every time tests run* ?!

Discussion in 'Testing & Automation' started by CodeSmile, May 4, 2022.

  1. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    I started using Code Coverage 1.0.1 with Unity 2021.3.1.

    Every time I run any test it opens another Explorer window! :mad:

    I tried playing with the settings. With "Auto Generate Report" unchecked there is no Explorer window opened, but the report is also not being updated as indicated by "Generated on" timestamp (as well as additional tests by adding/removing code).

    So I'm left with CC either being super-annoying, or disabled. Is there any way I can force it to generate reports WITHOUT opening a new Explorer window every time?
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    GOT IT!

    The internal class CoverageSettings has a flag revealReportInFinder that defaults to true. That flag doesn't have a corresponding setting in CodeCoverageWindow, therefore it is always true.

    I had to copy the package contents into the project to change that flag to false. Now I get reports without being annoyed, what a relief.
     
    Last edited: May 4, 2022
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Btw I keep getting oddly uncovered lines, like completely illogical. It tells me I haven't tested a method, but the method body is fully tested, things like that.

    For example:
    upload_2022-5-4_17-43-0.png
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Or this one:
    upload_2022-5-4_17-46-49.png

    Even without the line break in the constructor arguments I get empty lines marked as "not covered".
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Okay, it's working better now. I upgraded to CC 1.1.1 but that didn't work. I went back to 1.0.1 and cleared Data and History. Now I get all the lines highlighted correctly (100% coverage) and [ExcludeFromCoverage] also works correctly.
     
  6. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi SteffenItterheim. I have not been able to recreate this. It should not be the case that a new explorer window opens every time a report is generated, rather that a window opens the first time and it gets refocused (if it is open) when a new report is generated.

    However, if you navigate to another location in that window, then a new window will open.

    I am curious, does the same happen for you when you rebuild a project in the same location (File > Build Settings > Build)?

    Regarding the coverage errors you described above, these are more likely a result of the source being out of sync from the generated coverage data. For example, generating coverage data for VertexPositionNormal class, then editing the class (i.e. adding a new line) and generating a report. I understand this can be confusing and we plan to add a notification/warning in that case.
     
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    By „refocus“ you mean the window pops up in front? That‘s essentially the same issue. I‘m running a test means I‘m working with the Unity editor. I don‘t need to look at an Explorer window after the test, nor do I need to look at the coverage results after every test. There is already a flag in CC settings that controls this behaviour but it isn‘t editable in the CC settings window (CC 1.0.1). Adding that would fix the issue.

    Once the CC html is open in the browser there‘s really no need to look at the CC results in the filesystem. ;)

    I haven‘t tried making a build. Are you saying that in order to get full coverage results (ie „in sync“) I need to make builds? I‘ll certainly give that a try. I thought that just running the tests suffices, and adding more code to a class while also adding a test for the new code should „cover“ it.

    PS: The fact that it opens new Explorer windows every time on my machine could be due to me using Directory Opus as the default explorer handler. I can imagine this could cause the „is that window already open?“ check to fail. Regardless, whether it‘s a new window, or the same, it pops up. That‘s focus stealing behaviour.
     
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    I'm on a MacBook now and can confirm that if there was already a Finder window opened, the existing one is refocused.

    Nevertheless annoying since every time I run a test Unity editor loses focus, and if I wanted to see Coverage results I would simply switch to the Browser.
     
  9. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi @CodeSmile - there is a new 'Auto Open Report' option in version 1.2.0 which disables opening the finder/explorer window if unchecked.
     
    bdovaz and CodeSmile like this.
  10. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Cool, thanks for letting me know! :)