I’m trying to setup unit testing for my project. Although most of my logic is going to reside in regular C# classes, certain things are going to have to live in MonoBehaviors (for instance, I’d like to test whether the component gets attached, or whether it even makes a call to the game logic in certain scenarios).
So I tried setting up nUnit and just including a reference to Assembly-CSharp and testing that. No luck, unity won’t let you run its dlls outside of Unity.
So I went to TestRunner and tried to create an EditMode Test folder, and create a simple test
[Test]
public void UnitTest1SimplePasses() {
Assert.IsTrue(new GameStateManager().Test());
}
But this fails because Unity can’t see the GameStateManager class (it’s defined in the Assets folder). While Visual Studio compiles correctly, Unity displays:
Assets/EditModeTests/UnitTest1.cs(10,27):
error CS0246: The type or namespace
name `GameStateManager’ could not be
found. Are you missing an assembly
reference?
Looking at the videos from the Unite 2017 conference (https://www.youtube.com/watch?v=MWS4aSO7HAo), she’s clearly doing some sort of manipulation with Unity classes, so is MonoBehavior just special?
Am I doing something wrong in my setup, or is it really impossible to unit test logic in those classes?
Thank you for any help.