mercredi 29 janvier 2020

Unity testing Singleton with NUnit

I have a Unity Project which should create a HoloLens Application. Now i want to test some of my Code in Unity with NUnit. I created some PlayMode tests

public class Test
{
    private GameObject empty;

    [SetUp]
    public void BeforEveryTest()
    {
        empty = new GameObject();
        empty.AddComponent<MainController>();
    }
    // A Test behaves as an ordinary method
    [Test]
    public void MainControllerGetInstance()
    {
        Assert.IsNotNull(MainController.Instance);
    }
}

This is the Singleton I want to test

public class MainController : Singleton<MainController>
{

[SerializeField]
private GameObject SomePref;

private void Start()
{
    SomePrefab.SetActive(true);
} 
}

I get an error that SomePref is not set to an instance of an object, but I can't set it up because its a private seralizedfield. Now what is good practice to erase that error. I know, I could use Resource.Load in the Start Methode from MainController, but is this the good way?

Aucun commentaire:

Enregistrer un commentaire