Search Unity

Unit testing setup for ECS

Discussion in 'Data Oriented Technology Stack' started by Roobubba, Aug 6, 2019.

  1. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    9
    I've been trying to set up Unit Testing for my project under ECS, but am hitting a brick wall at the moment.

    Unity version: 2019.2.0b9
    Test Framework: 1.0.18
    Custom NUnit: 1.0.0
    Unity.Physics: preview-0.2.0
    Entities: preview-0.1.0

    I tried following the video from over a year ago from infallible code:

    to set up unit testing using a custom asmdef file, which works as far as being able to test the built-in unity code, but I cannot access any of my own code this way. I tried everything I could work out from the thread about this: https://forum.unity.com/threads/how-to-unit-test-where-is-the-unity-entities-tests-namespace.540251/ but to no avail.

    I already had some unit testing working for some static helper classes I have to read/process input files, but when I create a custom asmdef as is done in all the unity examples, that all breaks as it no longer access my own code base at all, and of course I can't test any of the ECS parts of my code without some setup - and this is my brick wall.
    I tried making specific namespaces for my code, but that didn't work. I tried looking at the Unity.Physics and Unity.Mathematics test examples, but they don't help: I simply can't reference my namespaces like they do. I tried tinkering with the manifest.json but got nowhere (and if we're being critical, this really shouldn't be required anyway).

    Most grateful for any help to resolve this!
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    Is your own code in a asmdef? All you need to do is add that as a reference and it should be usable in the test project.
     
  3. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    9
    My code is just as you normally would code in unity, so not sure how you reference that, would that be the Assembly-CSharp?
    Add what reference to where?
     
  4. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    54
    So typically, if you want to write unit tests, there's a testing folder with an assembly definition file. If you would like to add references to your own code base on the testing assembly, your own code base should have its own assembly definition.

    Then add your own code base's assembly definition to your tests.

    Scripts
    * MyCodeBase.asmdef
    * References: Unity.Entities.asmdef

    Tests
    * MyTestCodebase.asmdef
    * References: Unity.Entities.asmdef, MyCodeBase.asmdef
     
  5. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    9
    Ahh okay, thank you, we're getting somewhere now!

    Presumably this means all my using statements now have to be replaced by referencing explicitly within my project's .asmdef's "Assembly Definition References" section? Or not replaced but in addition to that?

    EDIT: And as I go through and try to add references, they're not all available (like Unity.Physics.Authoring and Unity.Rendering aren't in the list).
     
    Last edited: Aug 6, 2019
  6. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    9
    Update:
    The Unity.Physics.Authoring was hidden under Unity.Entities.Hybrid (and likewise I found the rendering one under Unity.Rendering.Hybrid). The only assembly ref I'm missing now seems to be

    Library\PackageCache\com.unity.rendering.hybrid@0.1.1-preview\Unity.Rendering.Hybrid\LightComponent.cs(86,16): error CS0246: The type or namespace name 'ShadowUpdateMode' could not be found (are you missing a using directive or an assembly reference?)

    There appears to be no way to find out which assembly reference is needed, I've had to go through manually and add random ones in the hope that the errors go away. This seems incredibly clunky and wrong, I MUST be making a mistake here, it's just not at all clear, unfortunately. This is the first I've heard of .asmdefs, I've just been making games in unity normally, so it'd be good to have more info on this on the DOTS documentation as it's a massive departure from how I've done things before and I can't be alone in coming up against crazy problems just getting set up.

    EDIT: I spoke too soon. There's still a bunch of errors - I can't seem to reference whatever my using Unity.Rendering; was referencing for the RenderMesh component.
     
    Last edited: Aug 6, 2019
    soleron likes this.
  7. psuong

    psuong

    Joined:
    Jun 11, 2014
    Posts:
    54
    Well here 's info regarding assembly definitions:

    https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

    As for the figuring out which assembly has which, yes it's a bit clunky since some namespaces are in other packages so there's some cross referencing. As for the RenderMesh, it should fall under the Hybrid Renderer package, so Unity.Renderering.Hybrid.
     
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    I find the easiest way to find a reference is either

    - just to search for the file in your project view (make sure to tick in packages to search packages) and you can see the directory/assembly it is in

    upload_2019-8-7_10-28-13.png

    - just scope to it in your IDE (F12 rider, can't remember hotkey VS) and there is usually a very easy way to find the location, for example you can just mouse over with rider and from memory at the least with VS you can open containing directory.
    upload_2019-8-7_10-29-31.png


    Setting up asmdef is definitely a bit of a pain each time (especially if you split your code a lot) but it really only takes 30 seconds most of the time
     
    Last edited: Aug 7, 2019
    psuong likes this.
  9. Roobubba

    Roobubba

    Joined:
    Nov 5, 2015
    Posts:
    9
    unfoundreference.png I appreciate the replies, thank you.

    I've commented out all my code relating to the RenderMesh as, because the project wouldn't compile, there was no chance for the auto api updater to fire.
    There's still a dependency issue within the Unity.Rendering.Hybrid system. I cannot find any reference to ShadowUpdateMode except for within the LightComponent.cs script as shown in the image below. There's no reference to it in the project when I search the entire solution including external items in VS, or the project view in unity.
    The Unity.Rendering.Hybrid reference is already made in my Prot.asmdef.

    Looks like 2 separate issues:

    1) RenderMesh itself comes under Unity.Rendering which I cannot reference (not in the list and complains it's not there if I manually edit the asmdef file)

    2) LightComponent issue seems separate, where I have the reference it's complaining about but there's a further unknown reference within that code.

    From within the LightComponent script is this:

    Code (CSharp):
    1. #if HDRP_6_EXISTS
    2. using UnityEngine.Experimental.Rendering.HDPipeline;
    3. #elif HDRP_7_EXISTS
    4. using UnityEngine.Rendering.HighDefinition;
    5. #endif
    Neither of these preprocessor symbols is defined in my project, and neither of these references is available for me to add to my asmdef.

    At this point, I'd be very happy not to have any reference stuff going on and just let it compile everything all the time if I could *just get working*. But that seems not to be an option, as then I can't access both ECS and my own code simultaneously. :(

    EDIT forgot to add the image
     
  10. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    Take your code out of the asdmef.

    Let the app compile.

    Create an asdmef in an empty directory and set it up with your reference then copy code in.

    If you can't find an assembly to reference, check that it is actually in your project (com.unity.rendering.hybrid) otherwise add it via the package manager. I don't believe you can references that are part of your project just because they're a dependency.
     
    Roobubba likes this.
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,671
    The asmdef file generates the define using the constraint system, to be passed specifically to that assembly compilation. Check out the Asmdef file in hybrid rendering to see where it is setup.
     
  12. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    38
    I had the same issue after updating to Hybrid rendering 0.1.1-preview, but have not explicitly defined any asmdefs – I "solved" it by moving back to 0.1.0. Perhaps Hybrid rendering 0.1.1 is not as important to you at this time?
     
    soleron, Sonorpearl and Roobubba like this.
  13. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    431
    It is broken even with correctly defined asmdefs currently when using HDRP 6.9.1. That's because ShadowUpdateMode wasn't added to HDAdditionalLightData until 7.0.0.
     
    esc_marcin, Sonorpearl and Roobubba like this.
  14. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    106
    I think this is something broken.

    I also have this issue.

    "Library\PackageCache\com.unity.rendering.hybrid@0.1.1-preview\Unity.Rendering.Hybrid\LightComponent.cs(86,16): error CS0246: The type or namespace name 'ShadowUpdateMode' could not be found (are you missing a using directive or an assembly reference?)"

    Is there a way to fix it or just wait?
     
    Last edited: Aug 19, 2019
  15. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    431
    I dropped back down to Unity.Rendering.Hybrid version 1.0 (everything else is still 1.1) and am doing non-graphics-related work. You could embed the package and modify it if it is an absolute blocker.
     
  16. francois85

    francois85

    Joined:
    Aug 11, 2015
    Posts:
    640
    Trying for over an hour to get this to work, anyone have a fix ?

    "Library/PackageCache/com.unity.rendering.hybrid@0.1.1-preview/Unity.Rendering.Hybrid/LightComponent.cs(86,16): error CS0246: The type or namespace name 'ShadowUpdateMode' could not be found (are you missing a using directive or an assembly reference?)"

    EDIT reverted Hybrid to 0.1.0 and it works
     
  17. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    The light conversion in Unity.Rendering.Hybrid 0.1.1 is bugged with HDRP < 7 (so it requires 2019.3 to work)
     
  18. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    106
    Shameful and unprofessional to have such a breaking error in a production release and fixing it in the next release which is still in Beta but not the release people depend for production...
     
  19. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    Production release?

    Entities (and hybrid renderer in this case) is a preview package. It's a long way off being marked as a production release.

    You use at your own peril.