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

Question Unity test not finding game classes

Discussion in 'Testing & Automation' started by syjgin, Sep 24, 2019.

  1. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    136
    I have class to test with Game.Console namespace, but when trying to compile test with string
    Code (CSharp):
    1. using Game.Console;
    2.  
    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?
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    Does your Tests.asmdef reference the asmdef that your game code is in?
     
  3. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    136
    Here is asmdef file content:
    Code (CSharp):
    1. {
    2.     "name": "Tests",
    3.     "references": [
    4.         "UnityEngine.TestRunner",
    5.         "UnityEditor.TestRunner"
    6.     ],
    7.     "includePlatforms": [
    8.         "Editor"
    9.     ],
    10.     "excludePlatforms": [],
    11.     "allowUnsafeCode": false,
    12.     "overrideReferences": true,
    13.     "precompiledReferences": [
    14.         ""
    15.     ],
    16.     "autoReferenced": false,
    17.     "defineConstraints": [
    18.         "UNITY_INCLUDE_TESTS"
    19.     ],
    20.     "versionDefines": []
    21. }
    How it looks in editor:
    upload_2019-9-24_22-9-41.png
    How to include assembly into .asmdef? Adding another item to "references" not works
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,649
    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.
     
  5. syjgin

    syjgin

    Joined:
    Feb 13, 2015
    Posts:
    136
    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
     
  6. lameduck

    lameduck

    Joined:
    Oct 1, 2020
    Posts:
    1
    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.