lundi 4 janvier 2021

Member fields not initialised in unit tests when set in inspector for unity

I have fields that are set in the inspector. enter image description here

The length of this array is then printed to the console when the game plays as expected

        public void Start() {
            Debug.Log(bootstrapData.Length);
        }

        public void printData()
        {
            Debug.Log(bootstrapData.Length);
        }

But when I run a test calling the printData in play mode the bootstrapData is null as they are not set from the inspector I am assuming.

[UnityTest]
        public IEnumerator test()
        {
            GameObject go = new GameObject();
            SpriteBootstrap spriteBootstrap = go.AddComponent<SpriteBootstrap>();
            spriteBootstrap.printData(); // null pointer here, data not set

            //... other irrelevant code            
        }

Is this normal behaviuor and can I get around this without manualy setting the data in the test.

Aucun commentaire:

Enregistrer un commentaire