Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to organise test code?

Discussion in 'Entity Component System' started by xseagullx, Sep 11, 2022.

  1. xseagullx

    xseagullx

    Joined:
    Nov 7, 2019
    Posts:
    24
    I'm having a little trouble with organising tests in my project. I keep my code in small packages, and they usually follow this structure.
    Code (CSharp):
    1.  
    2. /
    3. --/Authoring (separate assembly)
    4. --/Runtime (separate assembly)
    5. --/... (other resources, e.g. models, prefabs, all in folders / subfolders)
    6. --/Tests (separate assembly, autoReferenced: false)
    7.  
    Problem is, that test code (systems and components) leaks in the global context (those systems will be visible in the World, in all Editor windows, and clutter the space (they don't cause issues, as they only run with test components, but still).

    How do I avoid it? Ideally I want to still be able to run my tests, but don't have them leak in the "production" code. I tried separate test setup, where they are in a project of their own and invisible to Unity, but that had some problems making it incompatible with DOTS, and i mostly need to test systems and their interactions.

    Another similar question is about samples, as they do have exactly same problem, but I think with those it's kinda inevitable, and I'd better just put them in the package of their own.
     
    Last edited: Sep 11, 2022
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Well tests should live in an editor only assembly so they won't make production. But it is annoying to have test systems appear in play mode in the editor so you can put this little snippet of code in an AssemblyInfo.cs file in the test assembly

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [assembly: DisableAutoCreation]
    which stops all systems being auto created in the test assembly and your tests are just responsible for creating the systems they need to test.
     
    xseagullx and Anthiese like this.
  3. xseagullx

    xseagullx

    Joined:
    Nov 7, 2019
    Posts:
    24
    Thank you, Tertle! That solves majority of the problems!