Unity test not finding game classes

I have class to test with Game.Console namespace, but when trying to compile test with string

using Game.Console;

there are such error generated:
Assets/Scripts/Tests/ConsoleTest.cs(6,7): error CS0246: The type or namespace name ‘Game’ could not be found (are you missing a using directive or an assembly reference?)
Tests.asmdef is exists with default settings. Unity version is 2019.2.3f1 Maybe, some additional setup is needed?

Does your Tests.asmdef reference the asmdef that your game code is in?

Here is asmdef file content:

{
    "name": "Tests",
    "references": [
        "UnityEngine.TestRunner",
        "UnityEditor.TestRunner"
    ],
    "includePlatforms": [
        "Editor"
    ],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": true,
    "precompiledReferences": [
        ""
    ],
    "autoReferenced": false,
    "defineConstraints": [
        "UNITY_INCLUDE_TESTS"
    ],
    "versionDefines": []
}

How it looks in editor:
4996652--488150--upload_2019-9-24_22-9-41.png
How to include assembly into .asmdef? Adding another item to “references” not works

You need to have an asmdef for your game code as well, and then add it to the ‘Assembly Definition References’ section in your Tests.asmdef.

But how can I create it? https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html this is not covered here. When I select “Assets->create->Assembly defeinition”, this just adds another equal asmdef file

When I select “Assets->create->Assembly defeinition”, this just adds another equal asmdef file

Yes, then you go back to the directory where your Test.asmdef lives, click on it, and in Assembly Definition References add that asmdef file to it.

1 Like