dimanche 23 août 2015

Cannot unit test scripts in Unity

Following the Unity unit test tools tutorial, I wrote a simple test.

using NUnit;
using NUnit.Core;
using NUnit.Framework;
using Esk.Gameplay;
using Esk.Gameplay.Players;

namespace Esk.Tests
{
    [TestFixture()]
    public class GameControllerTest 
    {
        [Test, Description("All properties must be coherent.")]
        public void Initialization()
        {
            var gm = new BotGameController();

            Assert.NotNull(gm.PlayerOne);
            Assert.NotNull(gm.PlayerTwo);
            Assert.NotNull(gm.TurnController);
            Assert.NotNull(gm.EventQueue);

            Assert.False(gm.GameStarted);
            Assert.Null(gm.CurrentPlayer);

            Assert.Equals(gm.PlayerOne, gm.HumanPlayer);
        }
    }
}

The problem is that the test code is in the Editor folder and thus is compiled into the Assembly-CSharp-Editor assembly. Therefore, although there is no syntax or semantic error shown in MonoDevelop, whenever I move into Unity it gives me a list of errors similar to this

Assets/Editor/Tests/GameControllerTest.cs(15,38): error CS0246: The type or namespace name `BotGameController' could not be found. Are you missing a using directive or an assembly reference?

Whilst BotGameController belongs to the Esk.Gameplay namespace.

Notice that the Assembly-CSharp assembly is by default included in the list of references of Assembly-CSharp-Editor.

On the contrary, if I bring the test script outside of the Editor folder, it doesn't find the NUnit namespace.

It seems that noone ever encountered such problem and thus I couldn't find any clue on Google. However, it appears to me a pretty trivial issue

Aucun commentaire:

Enregistrer un commentaire