Question by
NickTemple · Jun 13, 2018 at 05:26 AM ·
serializationtesting
Deserialization during Unit Testing
Trying to perform unit tests on a Monobehaviour, and coming across an issue where the Awake()
function is throwing an exception because fields that I would usually fill in the GUI are null.
I created a seperate Construct()
function to set these fields, but the Awake()
function is always called first, because it is called when GameObject.AddComponent()
is called.
Other MonoBehaviours depend on this object to initialise these values in Awake()
, so I can't simply change it to suit the test method:
[UnityTest]
public IEnumerator SignInRequest()
{
var go = new GameObject();
var data = Resources.Load<Example>("Path\\To\\Data");
var service = go.AddComponent<Service>();
// Awake is called during AddComponent ^ throws exception because GUI properties missing
service.Construct(data);
}
Is it possible to set these properties before Adding the component in the Unity Test Runner system?
Comment