unity 2019.1.0f2 removes references of other projects from test project

I’m trying to learn Unity’s idiosyncrasies for unit testing. I’m not sure if I’ve encountered a bug with 2019.1.0f2 or if there is something not covered by the Unity documentation for unit tests.

I can’t get past the errors:
Fix compilation issues before running tests
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Error CS0246 The type or namespace name ‘StephenLujan’ could not be found (are you missing a using directive or an assembly reference?)

I got to this by first realizing that I couldn’t unit test anything that utilized the Unity library without some security exception, and I had to use the documentation here Unity - Manual: Unit Testing to “Create EditMode Test Assembly Folder” and “Create Test Script In Current Folder”, use the “UnityTest” attribute instead of just test, and running the test from test runner in the Unity Editor instead of Visual Studio.

So I can clear the errors in Visual Studio and make sure everything compiles from VS by simply adding references of the default Assembly-CSharp and Assembly-CSharp-Editor to the test project that Unity created, and rebuilding, but that doesn’t remove the error from the Unity Editor or let it run tests. When I try restarting the Unity editor the references to the other projects are removed from the test project. I also tried manually editing the Tests.asmdef file to

{
  "name": "Tests",
  "references": [
    "Assembly-CSharp",
    "Assembly-CSharp-Editor"
  ],
  "optionalUnityReferences": [
    "TestAssemblies"
  ],
  "includePlatforms": [
    "Editor"
  ],
  "excludePlatforms": [],
  "allowUnsafeCode": false,
  "overrideReferences": false,
  "precompiledReferences": [
    ""
  ],
  "autoReferenced": true,
  "defineConstraints": [],
  "versionDefines": []
}

but this doesn’t seem to help anything. In the inspector, when I select the asmdef, it lists the references but has the message “The grayed out assembly references are missing and will not be referenced during compilation.”

Shouldn’t the default test project created by Unity’s test runner, automatically reference the other default projects created by unity? What am I missing?

What does your test script look like

I honestly don’t think it matters. I can’t test any code from my main project; I can’t even add a using statement for a namespace in it. In any case here it is.

using NUnit.Framework;
using StephenLujan.TerrainEngine;
using System.Collections;
using UnityEngine.TestTools;

namespace Tests
{
    public class UnityNoiseTests
    {
         [UnityTest]
        public IEnumerator NoiseOutputNotFlat()
        {
            Noise noise = new Noise(0, 0.1f, 5, 2.0f, 0.5f);

            float[] output = noise.GetNoiseSet(0, 0, 0, 1, 1, 1);
            Assert.AreNotEqual(output[0], output[1]);
            yield return null;
        }
    }
}

I had this problem, I added a new .asmdef to my scripts folder where my main code lives then added that to the test assembly. When I get home tonight I can double check

This looks like a reproducible bug for me with the following steps:

  • Create a new project
  • Create a new c# script from unity with this code namespace MainProject { public class Dummy { }}
  • Open the test runner in unity editor
  • Click Create EditMode Test Assembly Folder
  • Open the tests folder Unity created
  • In the test runner, click Create Test Script In Current Folder
  • Edit the test script to include using MainProject;
  • In the unity editor test runner click Run All

I would think that these simple steps, mostly done through the editor, should work. If not, the Unity documentation must be missing something important.

Again this is Unity 2019.1.0f2

There still remains either a bug in Unity or a gap in documentation, but your suggestion works for me.
I created an Assembly Definition in the store assets and then one in my code that referenced the store assets, then I referenced both from the tests assembly definition.

I’m an experienced programmer, but a Unity noob. I never read about the Unity Assembly Definitions before. This let’s me keep working. Thanks.

Be good to get Unity to clarify how this is meant to work. Im honesty not 100% sure

FYI I just ran into an issue with this. If you add a package make sure you add it to the assembly file in your script folder

See thread below, jump to end

https://forum.unity.com/threads/the-type-or-namespace-name-entities-does-not-exist-in-the-namespace-unity-are-you-missing-an-as.675676/#post-4523437