Reseting PlayMode Test Domain

I am new to Unity’s test framework.

I’m making playmode tests using [UnityTest] functions. Each script test a system and when running the tests individually they return successful but when running them all they break.

Tests appear to bleed into each other. Primarily singleton classes which I initiate using [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)].

Looking online some suggest using editmode tests and then using yield EnterPlayMode/ExitPlayMode and others suggest coding a reset state into the singletons but that is rather hard since this is not a new project but an old one I’m trying to implement tests in.

Is there a way to reset the test domain that I perhaps could implement in [SetUp] and/or [TearDown]?

If there isn’t a way to reload the playmode test domain then I think it’s easier to move the tests to editmode and using the yields.

I’ve never found a solution other than what you already noted: providing a reset state for singletons.

Honestly, this isn’t just a Unity thing. Singletons are notoriously annoying for automated testing for exactly reasons like this. If you can’t make them work as instanceable objects with static accessors as a singleton wrapper then your next best bet really is to provide yourself with some kind of reset method that returns everything to their default state. This is pretty much just how you do things like this.