Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity Code Coverage Package Preview

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

  1. Jamie_Robertson


    Nov 15, 2019
    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?


    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
  2. Unity-Nikos


    Unity Technologies

    Sep 30, 2015
  3. arthursb


    Nov 9, 2016
    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.

    Thanks Arthur

    1. Unfortunately not at the moment. We plan to add support for playmode tests in the player early 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
  4. Jamie_Robertson


    Nov 15, 2019
    @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?


    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.
    Last edited by a moderator: Sep 23, 2020