How to Unit Test? Where is the Unity.Entities.Tests namespace?

Hello!

So I recently moved from Unity 5 to Unity 2018 so I can work with the ECS. I'm running into some problems getting ECS Unit Tests running. I was attempting to follow this video.


- When I put my test script in an Editor folder, I am not able to find the Unity.Entities.Tests namespace, or the ECSTestsFixture base class. 3561751--286949--upload_2018-7-12_10-44-15.png

  • When I put my test script in a Tests folder, I can't find the Unity.Entities namespace. I don't think "Tests" was a special folder in Unity 5.3561751--286950--upload_2018-7-12_10-45-33.png

  • In the video, it looks like references to these namespaces were added to a "Assembly Definition" which also seems new to Unity. In the video, they are able to add packages like Unity.Mathematics or Unity.Entities.Editor.Tests. I don't see a list of any of these packages. Where can I find them?3561751--286951--upload_2018-7-12_10-48-7.png

Thanks for any help!

This is the point in the video where I can no longer follow.

3561753--286954--upload_2018-7-12_10-51-53.jpg

[quote=“GarthSmith”, post:2, topic: 707872]
This is the point in the video where I can no longer follow.

[/quote]

You can manually edit the asmdef file to include “Unity.Entities.Tests”. For some reason that inspector window broke again and doesn’t display assembly def references for the unity packages, although on several of the beta builds it was working for a while.

The Tests.asmdef file looked like JSON, so I added "Unity.Entities", "Unity.Entities.Tests", and ""Unity.Entities.Editor.Tests".

{
    "name": "Tests",
    "references": [
        "Unity.Entities",
        "Unity.Entities.Tests",
        "Unity.Entities.Editor.Tests"
    ],
    "optionalUnityReferences": [
        "TestAssemblies"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": [],
    "allowUnsafeCode": false
}

This allowed these references to appear in the Unity Inspector.
3562099--286994--upload_2018-7-12_15-37-18.png

However, the namespace is still missing in code.
3562099--286995--upload_2018-7-12_15-38-15.png

Both the .asmdef file and the AnnounceSystemTest.cs file are in a "Tests" folder. I'm on Unity 2018.1.7f1 with the Entities 0.0.12-preview.8 package.

Why is the namespace still not found? Are there any example projects with ECS tests included so I can see a working example?

If feasible, try deleting any *.rsp, *.csproj, and *.sln files generated by Unity and then reopening it.

If that doesn't work, you may need to not only clean those out but also do this additional step:

Exit Unity. Look for the project directory where "Assets" folder lives. Delete Temp directory (if it still exists) delete obj directory (if it exists). Delete Library folder. Reopening Unity should trigger a clean packages pull and recompile of your project.

Sorry to hear you're having trouble with this. Let us know if you get it working!

I have same issue as Garth-Smith. Unity.Entities.Tests.dll is not in Library/ScriptAssemblies. I am using 2018.2.2f1. Tried reimport all. Suggestions?

3589337--290645--UnityEntitiesTestsDll.png

I haven't run tests.
But i searched quickly my assets folder and found two.

Unity.Jobs.Tests.dll
and
Unity.Collections.Tests.dll

which are located in
Project folder -> \Library\ScriptAssemblies*
*But don't know, if this what you are looking for.

Thank you. I tried both and unfortunately neither had ECSTestsFixture defined. So I ended up installing "preview 2" of entities package which included Unity.Entities.Tests and copied ECSTestsFixture and its dependencies on EcsTestData varieties into my test code base for now. Also had to change World.Active to be static. Then reinstalled "preview 8" which is currently the latest version. Example from charlesmat ran and passed so it seems to work. I assume Unity will add Unity.Entities.Tests back in a later version.

I have the same problem, did they remove the ECS testing assembly in preview 8? I would love to try ECS test tools, being an essential part in data oriented design.

[quote=“orange-rabbit”, post:9, topic: 707872]
Thank you. I tried both and unfortunately neither had ECSTestsFixture defined. So I ended up installing “preview 2” of entities package which included Unity.Entities.Tests and copied ECSTestsFixture and its dependencies on EcsTestData varieties into my test code base for now. Also had to change World.Active to be static. Then reinstalled “preview 8” which is currently the latest version. Example from charlesmat ran and passed so it seems to work. I assume Unity will add Unity.Entities.Tests back in a later version.
[/quote]I installed Unity 2018.2.5f1 which allowed me to try importing Entities 0.0.12-preview.2 and Entities 0.0.12-preview.11.

However, I still don’t see a list of any references to add to my .asmdef file. I still cannot find the Unity.Entities.Tests namespace anywhere.

Has anyone been able to get testing working with Entities on a fresh install of Unity?

[quote=“GarthSmith”, post:11, topic: 707872]
I installed Unity 2018.2.5f1 which allowed me to try importing Entities 0.0.12-preview.2 and Entities 0.0.12-preview.11.

However, I still don’t see a list of any references to add to my .asmdef file. I still cannot find the Unity.Entities.Tests namespace anywhere.

Has anyone been able to get testing working with Entities on a fresh install of Unity?
[/quote]
You have to:

  1. Click on your asmdef file to show it in the inspector (for example Main.Tests.asmdef)
  2. In inspector/References click a “+” sign to add a new reference field
  3. In Project explorer locate asmdef file of your reference (for example packages/unity.entities.tests/unity.entities.tests.asmdef)
  4. Drag and drop this file to your new references field
  5. Click apply to confirm changes

EDIT: I have noticed you referenced the tutorial from Infallible Code in your original post. While I like Charles Amat’s tutorials, this one could be done better. Referencing Unity’s test base class is unnecessary shortcut, he should explain how to create your own test base class. It is pretty easy and much better option then deriving from ECSTEstsFixture, which could be changed anytime in the future and break your code.

You need to edit the asm def file by hand right now in 18.2 I believe. (The asmdef files of readonly packages don't show up in object picker)
The issue will be fixed in 18.3.

[quote=“Fido789”, post:12, topic: 707872]
3. In Project explorer locate asmdef file of your reference (for example packages/unity.entities.tests/unity.entities.tests.asmdef)
[/quote]
I have this problem too in 2018.2.13f and in 2018.3.0b6.

I tried double click in inspector and copy whole unity.entities.tests folder to my Assets/Tests folder
But it does not work too.

I copied ECSTestsFixture.cs and TestComponents.cs to my Tests folder, also I have fix includes.
And it seems that it works.

1 Like

Using Unity 2019.1.0a10, Unity.Entities 0.0.12-preview.21 issue still persists.

This suggestions works!

Thanks :)

Something is definitiely broken with the assembly definitions for Unity.Entities.Tests.
When I include only Unity.Entities in my asmdef, I can reference the namespace "Unity.Entities" in a script.
When I add Unity.Entities AND Unity.Entities.Tests, I cannot even reference the namespace "Unity.Entities" at all.

Works fine for me, but I have to set it up a specific way.

The main thing is, manifest.json must include the "com.unity.entities" as a testable, this is what mine looks like

  "testables": [
    "com.unity.collections",
    "com.unity.entities",
    "com.unity.jobs",
    "com.unity.test-framework.performance"
  ],

Then your test asmdef should reference both the tests and the base package, mine looks like this (with a few extra libraries in there)

{
    "name": "Shattered.Testing",
    "references": [
        "Shattered",
        "Unity.Mathematics",
        "Common",
        "Zenject-TestFramework",
        "Unity.Entities",
        "Unity.Entities.Hybrid",
        "Unity.Collections",
        "Unity.Entities.Tests",
        "Unity.Transforms",
        "BovineLabs.Entities"
    ],
    "optionalUnityReferences": [
        "TestAssemblies"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": false,
    "precompiledReferences": [],
    "autoReferenced": true,
    "defineConstraints": []
}
12 Likes

omg, I have been wondering for months if it is a bug and I have to copy the test fixture class to my own asmdef.. so this "testables" is only editable via text editor?

I believe so and adding it will solve all your issues

Adding those testables on Unity 2019.1.0a14 get me:

Library\PackageCache\com.unity.entities@0.0.12-preview.23\Unity.Entities.PerformanceTests\EntitySerializationPerformanceTests.cs(136,10): error CS0246: The type or namespace name 'PerformanceTest' could not be found (are you missing a using directive or an assembly reference?)

Here are my manifest.json

{
  "dependencies": {
    "com.unity.burst": "0.2.4-preview.41",
    "com.unity.collections": "0.0.9-preview.11",
    "com.unity.entities": "0.0.12-preview.23",
    "com.unity.jobs": "0.0.7-preview.6",
    "com.unity.mathematics": "0.0.12-preview.19",
    "com.unity.package-manager-ui": "2.1.1",
    "com.unity.rendering.hybrid": "0.0.1-preview.3",
    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "com.unity.modules.imgui": "1.0.0",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.particlesystem": "1.0.0",
    "com.unity.modules.physics": "1.0.0",
    "com.unity.modules.physics2d": "1.0.0",
    "com.unity.modules.screencapture": "1.0.0",
    "com.unity.modules.terrain": "1.0.0",
    "com.unity.modules.terrainphysics": "1.0.0",
    "com.unity.modules.tilemap": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unityanalytics": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    "com.unity.modules.vehicles": "1.0.0",
    "com.unity.modules.video": "1.0.0",
    "com.unity.modules.vr": "1.0.0",
    "com.unity.modules.wind": "1.0.0",
    "com.unity.modules.xr": "1.0.0"
  },
  "testables" : [
    "com.unity.collections",
    "com.unity.entities",
    "com.unity.jobs"
  ]
}

and my Tests.asmdef

{
    "name": "Tests",
    "references": [
        "Unity.Entities.Tests",
        "Unity.Entities"
    ],
    "optionalUnityReferences": [
        "TestAssemblies"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": false,
    "precompiledReferences": [],
    "autoReferenced": true,
    "defineConstraints": [],
    "versionDefines": []
}