Search Unity

Any tip for hiding away test assembly for faster script reload?

Discussion in 'Testing & Automation' started by Wappenull, May 13, 2022.

  1. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    Using automated testing and Test Driven Development is cool!

    But when you go back to develop features and fixing bugs, which will happen most of the time, script compile time is now quite slower. Something like from 20 sec to 30+ sec.

    Which is understandable, because test asm sits on top of game asm:
    Base libs > game asm > test asm

    Every time I made a tiny edit to any game script, the test asm that sit on top of it also need to recompiled and reloaded, which is wasteful because i'm not even using the test yet, it is slowing down my development cycle.

    I know one possible solution is to:
    Move away all test folders from project, but that is not much elegant ^^;

    I'm expecting to write some kind of editor script to turn testing off/on by a flick of switch.
    I'm looking for an idea of HOW to hide those test from Unity, or prevent it to compile.
     
    eppsjustin050 likes this.
  2. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    53
    Ignoring the fact that I'd recommend using TDD while developing features and fixing bugs, I'll offer one suggestion to mitigate the issue, and another hack to do what you're asking for...

    My primary suggestion would be to split the project into multiple assemblies, and have very little functionality in the main assembly: this way the amount of tests that get recompiled for any code change is minimised. This is assuming you are writing tests for smaller units of the game, and not only tests that test the full game.

    The hacky workaround includes selecting only a platform you don't use in the test .asmdef. However, last time I checked, Unity doesn't offer a public way to modify assembly definitions from code (it's been a while since I checked, though). This means that you would either need to directly edit the json from code, or then access the internal
    UnityEditor.Scripting.ScriptCompilation.CustomScriptAssemblyData
    class by some means. I can't really recommend doing this, but it can be done through reflection or by taking a look at the
    InternalsVisibleTo
    attributes used in the containing assembly.
     
  3. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    sbergen thanks for the tip, I will look into it.

    > Edit and change away the target platform asmdef
    This is what I done for now by hand. If it cannot be controlled by editor script then that's a bit unfortunate...

    Now one possibility that came to me is renaming all test folder and prefix it with '.'
    As in https://docs.unity3d.com/Manual/SpecialFolders.html (Hidden Assets)
    This way it can stay where it is in project and not compiled (but beware not to commit this changes to git)

    I will experiment with it later and come back to this post. (possibly along with quick copy-paste of editor script for internet traveler)
     
  4. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    Hi, any internet traveler, I have succeed in my mission to reduce compile time by disabling test assemblies.

    What does it do?
    It searches for all ***.Test(s).asmdef files in Assets folder, then offer you to rename parent directory by prepending '.' (dot) to it, Unity will ignore import for these special folder name.
    Thus, effectively ignore all test assembly from importing.

    Here is the screenshot of the tool:
    Access it from menu Tools > Wappen
    upload_2022-5-30_17-32-42.png

    Here is the gist: (shove it somewhere in editor script folder)
    https://gist.github.com/wappenull/c03380929b9f579c9c2530390d313d30

    Known bug: will probably fail if some entry is contain inside each other, each test assembly location must be free, distinct path from each other.
    I wont cover these complex cases, please adjust source code yourself to suit your situation.