Search Unity

Resolved Unity Test Framework not importing namespaces

Discussion in 'Package Manager' started by GroovyKoala, Nov 30, 2022.

  1. GroovyKoala

    GroovyKoala

    Joined:
    Feb 16, 2022
    Posts:
    23
    Hi! I have just created a sample Unity Test Assembly folder and created a script.
    But while trying to import namespaces and other classes I have created it does not work:

    Code (CSharp):
    1. The type or namespace name 'ProcessUnit' could not be found (are you missing a using directive or an assembly reference?) [TestTUnit]csharp(CS0246)
    Have i forgot to add something to the Assembly? I have not found documentation about this, can someone please point out?
    upload_2022-11-30_18-36-2.png

    using Unity 2022.1.23f1 and
    upload_2022-11-30_18-36-59.png
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,005
    You need to add the Assembly where your to-be-tested classes are defined to the Assembly references list of the test assembly. Currently it only lists the two TestRunner assemblies.

    If your code isn‘t in an assembly definition you‘ll have to add one to be able to reference it in the test assembly def.
     
    GroovyKoala likes this.
  3. GroovyKoala

    GroovyKoala

    Joined:
    Feb 16, 2022
    Posts:
    23
    Alright, this solved the issue. Thanks you very much!
     
  4. jarlemag

    jarlemag

    Joined:
    Dec 12, 2020
    Posts:
    5
    I have the same issue I think, but I don't understand exactly how to perform the fix mentioned here. I have not actively created any custom namespaces or assemblies for my project except for the assembly which was created for testing and which my test script belongs to. Is there an automtically created .asmdef that covers my project as a whole? If so, where should I look for it? Or should I manually create an assembly for my non-testing project files?

    Edit: I figured it out now. I created an assembly definition file in my "Scripts" folder. After adding a reference to that file and to the pre-compiled TextMeshPro assembly in the "test" assembly definition file, my test script works and can use the classes/namespace in the scripts in my "Scripts" folder.
     
    Last edited: Feb 4, 2024