Search Unity

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

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Unable to reference scripts from testing project

Discussion in 'Editor & General Support' started by CaptainIsolation, May 16, 2020.

  1. CaptainIsolation

    CaptainIsolation

    Joined:
    Sep 26, 2018
    Posts:
    6
    I'm just learning how to implement tests in unity and I've been trying but apparantly failing to add assembly definition references to my testing project. I'm unable to reference the class from my test every time I try

    Folder structure is:
    upload_2020-5-16_22-23-33.png


    PlayTests.asmdef:

    Code (CSharp):
    1. {
    2.     "name": "PlayTests",
    3.     "references": [
    4.         "Scripts",
    5.         "UnityEngine.TestRunner",
    6.         "UnityEditor.TestRunner"
    7.     ],
    8.     "includePlatforms": [],
    9.     "excludePlatforms": [],
    10.     "allowUnsafeCode": false,
    11.     "overrideReferences": true,
    12.     "precompiledReferences": [
    13.         "nunit.framework.dll"
    14.     ],
    15.     "autoReferenced": false,
    16.     "defineConstraints": [
    17.         "UNITY_INCLUDE_TESTS"
    18.     ],
    19.     "versionDefines": [],
    20.     "noEngineReferences": false
    21. }
    Scripts.asmdef:
    Code (CSharp):
    1. {
    2.     "name": "Scripts",
    3.     "references": [],
    4.     "includePlatforms": [],
    5.     "excludePlatforms": [],
    6.     "allowUnsafeCode": false,
    7.     "overrideReferences": false,
    8.     "precompiledReferences": [],
    9.     "autoReferenced": false,
    10.     "defineConstraints": [],
    11.     "versionDefines": [],
    12.     "noEngineReferences": false
    13. }
    Still unable to reference the class in my testing script:
    upload_2020-5-16_22-25-28.png


    Scripts is showing up in the references:

    upload_2020-5-16_22-26-53.png



    What I've tried:
    - Starting the whole project from scratch, creating test folder & script from unity editor
    - Closing unity, visual studio, re-opening, cleaning solution then build
    - Deleted csproj, script.dll etc. then re-opened c# project
    - Using GUIDs for script references

    I seem to get the same issue every time and really don't think this is me, does anyone have any suggestions?
     
  2. CaptainIsolation

    CaptainIsolation

    Joined:
    Sep 26, 2018
    Posts:
    6
    As an update to this

    I've made 0 code changes, but the tests do run correctly

    I've opened the solution in Rider and it's displaying the references correctly too

    Looks like a VS bug
     
unityunity