Search Unity

Official Code Coverage Package - Discussion

Discussion in 'Testing & Automation' started by Unity-Nikos, Nov 14, 2019.

Thread Status:
Not open for further replies.
  1. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    The Code Coverage package has now been released. You can find the new introduction thread here: https://forum.unity.com/threads/1073831

    ---

    Use the Code Coverage preview package with the Test Runner to gather and present test coverage information. When you run your tests with code coverage enabled, you can see exactly which lines of your code are executed, in addition to whether the tests have passed or failed. For more details see Using Code Coverage with Test Runner.


    Code Coverage window

    Once a test run has completed, the Code Coverage package will generate an HTML coverage report showing which lines of your code are covered by tests. Code Coverage currently supports EditMode and PlayMode tests in the Editor. It also allows you to track the code coverage changes through time.


    HTML report

    If you don't have any tests, don't worry! The Code Coverage package offers a Coverage Recording feature which allows capturing coverage data on demand.

    coverage-recording.gif

    The Code Coverage package is available as a preview package via the Package Manager for Unity 2019.3 and above. See Installing Code Coverage. Please make sure to enable preview packages in the Package Manager, otherwise it won't be listed.

    Take note that preview packages are not considered ready for production use and might change before being verified for release.

    upload_2019-11-14_13-52-3.png
    Installing Code Coverage

    For more information see the Code Coverage package documentation.

    We look forward to your questions and feedback!
     
    Last edited: Mar 13, 2021
    t_tutiya, konsnos, WAYNGames and 13 others like this.
  2. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    I just tried it out and just gotta say, wow, this is an awesome tool to have at your disposal! I try to work with TDD where possible so I thought I had 100% test coverage in some of my submodules and with the help of this I immediately spotted som holes that could have meant bugs could creep in.

    I really like that I can see the history too :)

    It's nice that I can place the report in a folder of my choice as I want to test submodules separately and store the report in each submodule. Would it be possible to add some concept of "presets" so that I can define one test report for each submodule and then easily switch between them? As it is right now I would need to do this manually and must remember wehere each submodule stores its report.

    Also, it warns for poor performance when being turned on, is this only when you generate the report or does it have some kind of constant overhead?

    I'll try it out more and get back to you with more questions probably :)
     
  3. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi Mikael,

    thanks for the feedback and suggestions!

    Presets:
    This is a good idea and agree that having separate presets for separate reports would give more flexibility. Currently the results are saved under a <ProjectName>-opencov folder, so with presets this could be updated to <ProjectName>-<PresetName>-opencov. What we would not be able to do is to reflect the presets in the report (i.e. a single report with different presets)..for now at least. I will discuss it with the team and add it to the backlog, and post any updates here.

    Code Coverage performance overhead:
    When you check Enable Code Coverage in Preferences > General you enable access to the interface for the code coverage data that Mono exposes - see https://docs.unity3d.com/ScriptReference/TestTools.Coverage.html and https://docs.unity3d.com/Packages/c...0.2/manual/TechnicalDetails.html#how-it-works. This adds some overhead to the editor and lowers the performance, so it is not recommended to leave it on if you are not doing coverage testing. We are exploring changing this in the future. We will post any progress here.

    Thanks
    Nikos
     
    Last edited: Nov 18, 2019
    t_tutiya, GarthSmith and Mikael-H like this.
  4. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    Thanks for the clarification! I'll turn it off when not actively TDD:ing then :)

    Regarding presets, I'm sure whatever you guys come up with will be awesome. I don't think it is a super necessary feature, just nice to have.
     
    Unity-Nikos likes this.
  5. Aaron_Chan

    Aaron_Chan

    Joined:
    May 5, 2017
    Posts:
    2
    Is possible to use it in unity 2017?

    Answer:

    Unfortunately not as the Code Coverage API was introduced in Unity 2019.2
     
  6. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    Hello, I used code coverage tool in Unity 2020.1 today and I want to use this tool for a long time. However, I have encountered several problems. I don't know if it's my own operation problem or a tool bug.

    I wrote a demo to learn to use code coverage tool, which is a class including function add, sub, mul and div and a Print function:
    upload_2019-11-21_19-14-44.png
    Then I wrote a test class in playmode, including the test function of function add, sub, mul and div(not including print function).
    upload_2019-11-21_19-15-37.png
    Then I ran the playmode test and generated the code coverage,which is out of my expectation:
    upload_2019-11-21_19-16-15.png
    The functions which are tested by the test function are not covered and the print function which is not tested by the test function is covered!

    Then I found out that the reason why the Print function is covered is that I invoked that function in Start function. I can't understand why this is handled like this: Shouldn’t coverage be the part of the code being tested? The invoke of Print function is not in the test code.
     
  7. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    There is a second question. I added some log infomation in the add, sub, mul and div functions:
    upload_2019-11-21_19-17-43.png
    Then I ran the test, the result surprised me again:
    upload_2019-11-21_19-18-9.png
    The coverage is 100% now! I did nothing but add log statement in the class! I can't understand the result like this. Can you troubleshoot the answer? Thank you very much!! Looking forward to your reply!!

    (The website doesn't allow me to upload source code so I have to use picture instead, forgive me.)
     
  8. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi DavidWei1. I suspect it is due to Code optimization been set to Release mode. Code Optimization was introduced in 2020.1. Code Optimization mode defines whether Unity Editor compiles scripts in Debug or Release mode. Debug mode enables C# debugging and it is required in order to obtain accurate code coverage. To ensure Code optimization is set to Debug mode you can do one of the following:
    • Switch to Debug mode in the Editor (bottom right corner, select the Bug icon > Switch to debug mode)
    • Using the CompilationPipeline api, set CompilationPipeline.codeOptimization = CodeOptimization.Debug
    • Pass -debugCodeOptimization to the command line
    Please see https://docs.unity3d.com/Packages/c...ml#using-code-coverage-with-code-optimization

    Let me know if this helps. We are planning to do this automatically in the future.

    Thanks
    Nikos
     
    t_tutiya likes this.
  9. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    t_tutiya likes this.
  10. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    It works!! The coverage is 100% whether I have added logs or not.
    However, I still have a question. The meaning of coverage here is the coverage of the test code or the full coverage of all the code runs? As I didn't write the test code of Print function but I invoked that function in Start function, the coverage increased still. I am a bit confused.
    Once upon a time I used googletest to get the coverage of my C++ unit test, its coverage is only about the code I covered in my test code.
    Looking forward to your reply!!! Thank you very much!!
     
  11. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    @davidwe01 since Class1 is a MonoBehaviour, depending on how you initialise it in your playmode test (I cannot see that bit in the screenshots), I suspect that Start is triggered as the script gets added to the Scene, or perhaps it is already added in the Scene before you run your test
     
    t_tutiya likes this.
  12. Mikael-H

    Mikael-H

    Joined:
    Apr 26, 2013
    Posts:
    309
    @Unity-Nikos ok, so here's another slightly dreamy feature request :) Would it be possible to somehow use the test coverage report with SonarQube? That would really make this fit in well at work where we use SonarQube for static code analysis and over time test coverage measuring on all builds. Not sure how many would be interested in this but I suspect many in the industrial segment where Unity is part of a larger ecosystem would be...
     
  13. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    Hi, Nikos. I get a new question. I want to use batchmode to run unit test and get coverage report. How can I change Unity to debug mode using command line?
     
  14. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    I changed to use Unity2019.3.0b12, which doesn't have the little bug at its right bottom conner and the problem is solved!
     
  15. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    t_tutiya likes this.
  16. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    @Mikael-H try pointing SonarQube to the <project-name>-opencov folder located under CodeCoverage in the project's root folder or under the Destination folder.
     
    Mikael-H likes this.
  17. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    Hi Nikos, I have a new problem here. Can Code Coverage only be used to determine the coverage of which part of the code to test? There is a part of code in my project that is automatically generated and does not require test coverage, but if I simply specify Assembly-CSharp to include they will be included in my coverage as well. Is there a way to solve it? Looking forward to your reply!
     
  18. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
  19. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    May I ask if the using of the command line to filter out directory is available now?
     
  20. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    It will be in the next version of the package, 0.2.1-preview. We will post an update to this thread when this is live.
     
    Last edited: Nov 27, 2019
  21. DavidWei1

    DavidWei1

    Joined:
    Nov 21, 2019
    Posts:
    8
    Ok, thank you very much! You helped a lot!!!
     
    Unity-Nikos likes this.
  22. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,932
    As I understand it, the related tech this relies upon was added in 2019.2, not 2019.3. Does that mean we can manually install in .2 ?

    (Guess who is stuck with being standardized on 2019.2 for the next 6+ months :)...)
     
  23. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Technically yes, but there might be untested scenarios as we officially support 2019.3 and above. But feel free to try it and let me know if you experience any issues and I will try to help.

    [Unsupported] Package installation in 2019.2

    To get the package in 2019.2:
    • Install it in a new project in 2019.3
    • Go to the project's folder into Library/PackageCache and copy the com.unity.testtools.codecoverage@0.2.x-preview folder
    • Paste it into your 2019.2 project's Packages folder
    Please note that the Code Coverage package is officially supported in 2019.3 and above.

    It is highly recommended having the latest version of 2019.2 installed.
     
    a436t4ataf likes this.
  24. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    This tool is a little gem. It gives you a "birds-eye view" of your code.
    I used the code coverage option on a game I work on for a long time.
    I have found many non-obvious mistakes I did (as well as many obvious ones), very fast, just by running the game as usual and checking the code coverage results.

    You can change the name to "Bad code revealer" :)
    Much appreciated!
     
    Last edited: Dec 8, 2019
  25. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Updated package codename to "Bad Code Revealer", from the "Oath to Quality" series
    (Thanks Ippokratis!)
     
    Ippokratis likes this.
  26. Marakino

    Marakino

    Joined:
    Aug 31, 2018
    Posts:
    4
    Greetings!

    It seems no matter what I try, I\m unable to generate the coverage report in batch mode.

    I'm running it like this:

    Code (csharp):
    1.  
    2. /Applications/Unity/Hub/Editor/2019.3.0f6/Unity.app/Contents/MacOS/Unity \
    3.                     -batchmode \
    4.                     -projectPath . \
    5.                     -runTests -testPlatform editmode \
    6.                     -testResults ./build/editmode-results.xml \
    7.                     -enableCodeCoverage -coverageResultsPath ./coverage \
    8.                     -coverageOptions 'enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport' \
    9.                     -logFile /dev/stdout
    10.  
    It does create the /coverage/<project-name>-opencov/EditMode folder, but it's always empty.

    On the other hand, it works just fine when being run from within the Unity editor.

    Is there something obvious that I'm missing, or is this a known issue in the current version?

    Thank you in advance for any help!
     
  27. chrisj_unity

    chrisj_unity

    Unity Technologies

    Joined:
    Jun 26, 2018
    Posts:
    1
    Hi Marakino,

    I just tried your command line on a simple test project using the same version of Unity and the latest version of the coverage package (0.2.2-preview). It's working correctly for me.

    When you run the command, do you get a ./build/editmode-results.xml file? If so, could you check the file to make sure that some edit mode tests were actually run?
     
  28. Marakino

    Marakino

    Joined:
    Aug 31, 2018
    Posts:
    4
    Thank you so much for your reply, chrisj!

    I'm actually setting up my CI workflow and, while the editmode test results report is generated, I don't have any tests yet.

    This is probably the reason why it's not working for me.
    I assumed it would mimic the coverage report I get in the editor, showing 0% coverage.

    I'll definitely try again with some tests and come back here with my results.

    Again, thank you for your help.
     
    chrisj_unity likes this.
  29. Marakino

    Marakino

    Joined:
    Aug 31, 2018
    Posts:
    4
    chrisj, I can confirm that was the issue indeed - the coverage report is generated if at least one test is present.

    Thanks! :)
     
    Unity-Nikos and chrisj_unity like this.
  30. thuatsi01

    thuatsi01

    Joined:
    Mar 14, 2020
    Posts:
    2
    Greetings!

    I have some problems when try running UT in Unity and get code coverage. My command's that I'm running it like this:
    Code (CSharp):
    1. /Applications/Unity/Hub/Editor/2019.3.5f1/Unity.app/Contents/MacOS/Unity
    2.         -batchmode \
    3.         -projectPath . \
    4.         -runTests -testPlatform editmode \
    5.         -enableCodeCoverage
    6.         -coverageResultsPath {path_to_coverage_folder} \
    7.         -coverageOptions 'enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport' \
    8.         -logFile {path_to_coverage_folder_logs}
    But, I don't know why in the coverage folder was empty. I checked log and found the error, that like
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. (Filename: Library/PackageCache/com.unity.testtools.codecoverage@0.2.3-preview/Editor/CoverageFormats/OpenCover/OpenCoverReporter.cs Line: 685)
    Some more information:
    Unity version: 2019.3.5f1
    Code coverage version: codecoverage@0.2.3-preview.
    And the TestResults_xxx.xml file is still generated.

    Is there something that I'm missing?
     
    Last edited: Mar 14, 2020
  31. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
  32. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
  33. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    @Unity-Nikos My report does not appear to include coverage of [UnityTest] tests, see the screenshots:

    LocalPlayerTest ran and was successful, yet it is marked as not covered Screen Shot 2020-04-13 at 10.23.53 PM.png

    And yet, when I look at the coverage report, it is all red. Note that all my [Test] code is green, but all my [UnityTest] is red.
    Screen Shot 2020-04-13 at 10.24.47 PM.png
     
    Last edited: Apr 15, 2020
  34. Jamie_Robertson

    Jamie_Robertson

    Joined:
    Nov 15, 2019
    Posts:
    12
    @Unity-Nikos - Does this package work if the tests are run through the TestRunnerAPI?
     
  35. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi @goldbug - [UnityTest] tests are supported and included in the coverage report. We tested with https://github.com/vis2k/Mirror (closer to a reproduction project), run the tests included and all seems to work correctly. Tested with package version 0.2.3-preview on Unity 2019.3.9f1.

    It is puzzling that not a single UnityTest shows in the report for you. In the example you sent above, could you please replace the body of the UnityTest with the code snippet below, select Clear Data to clear any previous Coverage Data, make sure Generate HTML Report and Auto Generate Report are checked, and run your tests

    yield return null;
    Assert.IsTrue(true);


    Additionally, would it be possible to create a minimal project that reproduces the issue and ideally report a bug following https://unity3d.com/unity/qa/bug-reporting

    Thanks!
     
  36. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi @Jamie_Robertson - yes it does. You would need to make sure that the package is installed, code coverage is enabled and Generate HTML Report and Auto Generate Report are checked. Let us know if you have any more questions.
     
    Jamie_Robertson likes this.
  37. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    @Unity-Nikos Here is how to reproduce the issue:

    1) Clone this repo: https://github.com/MirrorNG/MirrorNG
    2) Open it in Unity 2019.3.7
    3) Enable coverage in editor settings if you haven't
    4) Open Code Coverage window and enable Generate HTML Report and AutoGenerate Report
    5) Open the test runner
    6) Click on PlayMode
    7) Click Run All
    8) Tests run and should all pass,
    9) Expand MirrorNG -> Mirror.Tests.Runtime.dll -> Mirror -> Tests -> NetworkClientTest
    10) observe LocalPlayerTest passes
    11) Report is generated, open index.htm (attached here)
    12) Expand Mirror.Tests.Runtime
    13) Click on Mirror.Tests.NetworkClientTest
    14) Click on LocalPlayerTest
    15) Observe the method body is all red
     

    Attached Files:

  38. Unity-Nikos

    Unity-Nikos

    Unity Technologies

    Joined:
    Sep 30, 2015
    Posts:
    87
    Hi @goldbug - thanks for sending the reproduction steps. We found that IEnumerable is used in [UnityTest] tests instead of IEnumerator. It should work if you update all the [UnityTest] instances to return an IEnumerator. It is so easy to make this mistake.
     
    goldbug likes this.
  39. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    Thanks that worked.

    I suggest displaying an error if a [UnityTest] returns anything other than IEnumerator,
     
    Unity-Nikos likes this.
  40. Jamie_Robertson

    Jamie_Robertson

    Joined:
    Nov 15, 2019
    Posts:
    12
    @Unity-Nikos It seems like neither `System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage` or `UnityEngine.TestTools.ExcludeFromCoverage` attribute is being respected by the package. Whenever I open up the report in SonarQube, anything I've marked with that attribute is still being included in the coverage report.

    Answer:

    We have added this to our backlog to fix. Thanks for reporting it.

    Edit: This is fixed in the next version of the package 0.4.0-preview
     
    Last edited by a moderator: Apr 28, 2020
  41. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,049
    @Unity-Nikos

    I am using Unity 2020.1b8 and I have found a different behavior than the 2019.3.x version.

    It turns out that in 2019.3.x I get 100% coverage in a script but in 2020 it tells me that there are several lines that are not covered when I know that they are.

    Researching it turns out that it is because in Unity 2020 you can switch between Debug/Release (Bottom right) and if it is in Release it seems that the behavior is different.

    I understand that it's a bug? Or is it that to analyze the code coverage you must be in Debug mode? It's very confusing, actually.

    Answer:

    Hi @bdovaz - thank you for the feedback. You are correct that Debug mode is required in order to obtain accurate code coverage information. This is not a bug as in Release mode the code is optimized and therefore not directly represented by the original code.

    There is a warning in the console and the Code Coverage window that explains that and we have added a popup message in the upcoming version of the package that is displayed when running tests or coverage recording on Release mode, which lets you switch to Debug mode too. For more information see Using Code Coverage with Code Optimization
     
    Last edited by a moderator: May 14, 2020
  42. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    991
    Hi, I'm testing my code and it seem to me that some line are counted as coverable whe nthey shoud not.

    upload_2020-5-16_18-45-12.png

    Basicly all the code of the class is covered but I endup with a 60ish % coverage due to the blanl/comment/signature lines.

    Edit : NVM, I cleared all coverage data and regenerate the report, it's fine now.
     
    Last edited: May 16, 2020
    Unity-Nikos likes this.
  43. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    991
    Hi @Unity-Nikos

    I'm using the coverage package for my project and I have question regarding the CRAP computation (I 'm new to that CRAP :p ).

    My understanding is that code coverage should be taken into account in the calculation. basically if the code is complex but it's well covered by test it's less CRAPpy than if it was not.

    The coverage report for my project returns some CRAP warning but it does not seem to take into consideration the code coverage.

    CRAP results
    upload_2020-6-27_11-55-55.png

    Coverage of methods
    upload_2020-6-27_11-57-17.png
    upload_2020-6-27_11-56-32.png

    If I take the first one and apply the formula to get the 56 score I just have to do 7^2 + 7, so cov(m) = 0

    For the second i have also to consider cov(m) = 0 to get the 42 score 6^2 + 6. where in fac I have 100% coverage so score should be 6^2 * (1 - (100/100))^3 + 6 = 6 so not CRAP.

    Answer:

    We have added this to our backlog to fix. Thank you for reporting it.

    Update:

    Fixed in 0.3.1-preview
     
    Last edited by a moderator: Jul 7, 2020
    Mikael-H likes this.
  44. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    991
    can't like my own post so thanks for the answer ;)
     
    Unity-Nikos likes this.
  45. Jamie_Robertson

    Jamie_Robertson

    Joined:
    Nov 15, 2019
    Posts:
    12
    Is there a reason that all assemblies are not included by default in the coverage options? As a corollary, is there an API for adding assemblies for coverage via script?

    Answer:

    Hi Jamie_Robertson, the idea behind not selecting all assemblies by default is that a high percentage of users would want to measure the code coverage of their code base and not of unity's & packages' code base. Instead only the assemblies that live under the Assets folder are selected by default.

    Adding an API to specify the assemblies makes sense. Thank you for the suggestion, I have added it in our backlog.

    Other ways to include all assemblies are:
    1. Press 'Select All' in the 'Included Assemblies' dropdown
    2. If running unity from the command line in batchmode, you can pass
      -coverageOptions assemblyFilters:+*
     
    Last edited by a moderator: Jul 3, 2020
  46. Jamie_Robertson

    Jamie_Robertson

    Joined:
    Nov 15, 2019
    Posts:
    12
    That answer makes sense. I was aware of the `assemblyFilters` options. I was specifically curious about the editor behaviour.

    Now that you mention the `assemblyFilters` option though, is the default value for that argument all assemblies? If that's the case, then would it not make sense then the default value in editor also be all assemblies?

    Update:

    Fixed in 0.3.1-preview
    • If `assemblyFilters` is not specified in `-coverageOptions` in batchmode, include only the assemblies found under the Assets folder
     
    Last edited by a moderator: Aug 4, 2020
  47. arthursb

    arthursb

    Joined:
    Nov 9, 2016
    Posts:
    2
    I have some questions:
    1. Is it possible to generate the Code Coverage report if I run my Play Mode tests in a platform besides the Editor? In other words, if I have Android specific code and run the test using the "Run all in player (Android)" option, will I get a report that includes these lines?
    2. Is it possible to generate a test build that executes only specific tests? It is clearly possible in the Editor using the "Run Selected" option, but I can't find a way to do the same thing in another player.
    3. Is it possible to label lines as untestable? For example, if I surround my code with #if UNITY_ANDROID and #endif and I test using the Editor, those lines should be excluded from the test.
    Answers:

    Thanks Arthur

    1. Unfortunately not at the moment. We plan to add support for playmode tests in the player next year.
    2. It is not possible from the UI to execute specific tests in player testing at the moment, but it is something that we will be adding to the test framework soon.
    3. If your code is surrounded by an #if block that isn't defined, then the compiler won't be generating any IL for that code, so it should already be excluded both from the tests and the coverage. If you run the tests in the editor and you are testing in Android platform, UNITY_ANDROID would be defined and therefore the code would be included in the coverage calculation & report.
    Note that in the next version of the package 0.4.0-preview you will be able to use the UnityEngine.TestTools.ExcludeFromCoverage attribute to exclude Assemblies, Classes, Constructors, Methods and Structs from the coverage calculation.
     
    Last edited by a moderator: Sep 22, 2020
  48. Jamie_Robertson

    Jamie_Robertson

    Joined:
    Nov 15, 2019
    Posts:
    12
    @Unity-Nikos - Glad to see the fixes going in for `ExcludeFromCoverage`! Thanks for the quick follow up.

    Curious, do you have a timeline for a non-preview release?

    Answer:

    Hi Jamie,

    we are currently in the process of getting the package out of preview. I will make sure to update on the progress in this thread.

    Edit:

    The Code Coverage package has now been released. You can find the new introduction thread here: https://forum.unity.com/threads/1073831
     
    Last edited by a moderator: Mar 13, 2021
  49. vvtthristov

    vvtthristov

    Joined:
    Jul 28, 2020
    Posts:
    2
    @Unity-Nikos There seems to be a regression with 0.4.1-preview.
    I am unable to build for android with it, while there seems to be no issue with 0.4.0-preview.

    The error:
    Code (csharp):
    1. ArgumentException: The Assembly WindowsBase is referenced by ReportGeneratorMerged ('Packages/com.unity.testtools.codecoverage/lib/ReportGenerator/ReportGeneratorMerged.dll'). But the dll is not allowed to be included or could not be found.
    2. UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1[T] alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at /home/bokken/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:158)
    3. UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, UnityEditor.BuildTarget target) (at /home/bokken/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:198)
    4. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /home/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
    5.  
    P.S. I have create a bug report (Case 1306557)

    Update:

    Thank you for filing a bug report. You can fix this for now by selecting only the Editor platform in the import settings of the ReportGeneratorMerged.dll in Packages > Code Coverage > lib > ReportGenerator. I will make sure this is fixed in the next version of the package.

    Edit:

    This is fixed in 0.4.2-preview. Apologies, I didn't realise that you can't do this if the package lives in Library/PackageCache.

    upload_2021-1-15_22-35-13.png
     
    Last edited by a moderator: Jan 21, 2021
  50. Oskiii

    Oskiii

    Joined:
    Feb 23, 2016
    Posts:
    13
    For others struggling with this error and noticing that you can't actually edit the .dll file settings as shown in the screenshot: you can edit them by first copying them over to a folder under Assets. After editing them, use File Explorer to drag them back to their original location.

    Or just wait for the fix, which is what I'm going to do.

    Update:

    Fixed in 0.4.2-preview
    • Updated Include Platforms to Editor only in the ReportGeneratorMerged.dll settings. Fixes an Android build error introduced in 0.4.1-preview (case 1306557)
     
    Last edited by a moderator: Jan 21, 2021
Thread Status:
Not open for further replies.