- Home /
Missing reference between 'Assembly-CSharp' and 'Tests' assembly, created with Assembly Definition
I try to create some NUnit-Tests for my HoloLens-Unity project. To test in PlayMode, I added a "Tests" folder with a Assembly Definition file:
{
"name": "Tests",
"optionalUnityReferences": [
"TestAssemblies"
]
}
This works fine and I can run some empty functions with Test and UnityTest attribute. Then, I created a MonoBehaviour in my "Assembly-CSharp" project. But now, it isn't possible to add/create a reference between my "Tests" project and "Assembly-CSharp" project.
I found no way in VS17 and Unity to add this reference. When I add
"references": [ "Assembly-CSharp" ],
directly to my Assembly Definition file, there appears a error in Unity "Assembly has reference to non-existent assembly 'Assembly-CSharp' (Assets/Tests/Tests.asmdef)".
Unity version: Unity 2018.1.6f1
Also experiencing this issue as well. In visual studio I can go into project dependencies for the Test project and add in "Depends on Assembly-CSharp" but in unity. I keep getting error messages like
Assets/Scripts/Zenject/Tests/SaveUnitTests.cs(3,22): error CS0234: The type or namespace name `Characters' does not exist in the namespace `ChrisTutorials'. Are you missing an assembly reference?
Been trying to figure this out for Zenject or just NUnit alone. Can't seem to get classes I've writen to be usable in the Unit tests.
Answer by bradford · Dec 31, 2018 at 04:32 PM
Hey, not sure if you ever figured this out but I encountered similar problems and was able to document a solution here:
To briefly elaborate, most of the code that you write in unity3d is stored in an assembly called Assembly-csharp.dll. For reasons that are beyond me, Unity doesn't let you reference this assembly from test code. However, you can make an assembly definition for your code under test, and reference that instead. Furthermore, if you are using editmode tests (it doesn't look like you are), you'll need to put your tests underneath a folder called 'Editor'.
I can't explain what's going on behind the scenes. I'm personally unhappy that Unity forced me to go through these steps and it makes me think that testrunner is a half baked feature that's not yet ready for public consumption. The lack of engagement in this and other forums make me question my commitment to Unity.
Your answer
![](https://koobas.hobune.stream/wayback/20220612172519im_/https://answers.unity.com/themes/thub/images/avi.jpg)