Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Package manager, Custom Assemblies and Unit testing

Discussion in 'Package Manager' started by WAYNGames, May 3, 2019.

?

Vote for preferred suggestion

  1. 1

    0 vote(s)
    0.0%
  2. 2

    0 vote(s)
    0.0%
  3. 3

    0 vote(s)
    0.0%
  1. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    Hello,

    Not sure I'm in the right section of the forum but here it goes.
    I'm working on a project with lost of the DOTS preview package.
    So far I had fun playing with it and now I'd like to get more serious about building something.

    So I want to do unit tests. My issue is to do so I need to add a test assembly that require a reference to my source code. And to do that I have to make a custom assembly because I can't find the auto generated one in the reference list for the test assembly.

    Problem as soon as I add a custom assembly I lose all references those imported through the package manager. and adding them all manual is a pain...

    I'm new to unit testing unity code so I may be doing things wrong but I would be great if this process could be more straight forward.

    I have some of suggestions but no idea what would be best :
    1) Have the custom assembly (and maybe also to the test assembly) automatically updated when packages are imported
    2) Not having to make a test assembly to exclude the test code from the build but use a special folder 'Tests' like the Editor one.
    3) Being able to reference the auto generated assembly in the test assembly without the need of custom assembly.

    Also It would be great if adding an assembly reference could bring all its dependencies with. Like the packages manager does with the packages.
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
  3. HaraldNielsen

    HaraldNielsen

    Unity Technologies

    Joined:
    Jun 8, 2016
    Posts:
    136
    Hi @WAYN_Group
    When you use Asmdef you need to be more explicit, its the tradeoff of using it. But you get faster compilation times and also nice separation.
    The reason that its faster is if some method in a Asmdef changes, only the Asmdef's that directly references the changed Asmdef needs to be recompiled. So automatically just adding references to an Asmdef is not really what you want, otherwise, you will lose this ability.
    Special folders are something we have used for a long time in Unity (Editor, Plugins ect), and this is something Asmdef's are taking a step away from, so the User have the power of making the choices. A User can do the same thing with Asmdef's as with special folders, and beyond that. Ie handling references depending on need.

    Using Asmdef's for testing will result in Test assemblies and all its references will only get included in player builds when you are actually running tests. This is why Test Asmdef's are not auto referenced by auto generated assemblies.

    You can have tests that are just part of your auto generated assembly. Look into the Test Runner manual on "Enable playmode tests for all assemblies.". This though results in your project including tests when Building Players, even for Release, and would result in your Player build size being bigger because of these extra things that you dont need when not running tests.

    Hope this gives some clarity.
     
  4. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    @HaraldNielsen
    I hear you but I fail to see the difference between adding let's say the burst assembly reference to my custom assembly and having the package manager do it when I import the burst package. Also adding assembly dependencies when referencing a new assembly seems abvious for me because otherwise I would not be able to use the one I just referenced.
    Adding the Entities package to my project does imoport all it's dependencies...

    So if on import from the package manager it auto update the assembly reference and on adding an assembly reference it also add its dependency I would not have to set everything up (the exact same way) manually.
    And it will not remove the benefit of having assemblies (faster compiles, separaration,...)
     
  5. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    Sorry realized while adding assemblies manually that you don't need all of them just the one necessary to compile your code. So although Entites package relies on Burst package you d'ont need burst assembly reference if you don't use it in your code.

    Just means that I'll have to add reference as needed and not rely on intelesense to tell me the possibilities of a package.