I try to make a simple nunit test within Unity, but get missing reference
error when i try to reference a MyScript
Project setup:
├── Assets
├── Scenes
├── Scripts
│ └── MyScript.cs
│ └── NewAssembly.asmdef -> see below "what i tried"
├── Tests
│ ├── MyScriptTest.cs
│ └── Tests.asmdef
Tests.asdmdef (created by Unity)
{
"name": "Tests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
MyScriptTest.cs:
using NUnit.Framework;
public class MyScriptTest
{
[Test]
public void SomeTest()
{
var obj = new MyScript(); // Error CS0246 The type or namespace name 'MyScript' could not be found (are you missing a using directive or an assembly reference?)
}
}
MyScript.cs
using UnityEngine;
using TMPro; // see below "What i tried"
public class MyScript : MonoBehaviour {}
Unity: 2030.3.37f1
Visual Studio: 2019 (Version 16.11.20)
What i tried
I tried to solve the problem with how-to-set-up-unit-tests-in-unity-and-fix-missing-assembly-reference-error by creating a Assemply Definition in Scripts/. This solves the error in MyScriptTest.cs
, but then i got tons of other errors in my (previously working) scripts like Assets\Scripts\MyScript.cs(2,7): error CS0246: The type or namespace name 'TMPro' could not be found (are you missing a using directive or an assembly reference?)
Any help is welcome! I can't believe this is so complicated....
Update:
Above was just a small example of the problem. I have around 46 issues like this in my project (many of the link to external libraries or own classes which i can't find the suitable reference by its name), so having an assembly reference for every single using
in my project just to do unit test work is not acceptable. Is this really the only way to do unit test work in Unity?