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?