How to run tests for multiple settings that can't be changed in PlayMode?

I have some tests that I need to run against different settings that can’t be changed in PlayMode.
These settings are currently (I might need others):

  • color space
  • XR rendering mode

Ideally, I’d like to have the ability to tell a specific test to leave playmode, change some setting, re-enter playmode and run the test. Is that possible? Or is there a workaround that doesn’t involve “change settings manually, then run the tests”?

  • write an edit mode UnityTest
  • yield return new EnterPlayMode();
  • run test
  • yield return new ExitPlayMode();

caveats:

  • enter play mode causes a domain reload (*), non-serialized state (including test local variables) is lost
  • this implies changing mode for each test, can be time-consuming if you have many tests

(*): 2019.3 introduces the possibility to skip it, but can break stuff (static variables, singletons, [ExecuteInEditMode] scripts, etc…)

Hm, that sounds it would basically turn the Play Mode tests to Edit Mode tests with hacky playmode then? I see… doesn’t sound ideal. But nice workaround, thanks.

@fherbst are these settings modifiable via some editor API?
if they are, you can basically create a play mode test that will set the required settings before it executes, then restore them to what they were as the test completes.

The test itself should not take care of exiting playmode and running the next test in line.

Yes, there’s an API, but at least the Editor warns (in Project settings) that these can’t be changed at runtime.

They will not be changed at runtime. You will have a bunch of tests. As a pre-step for each one of them, you will call this AOI to set whatever settings u need, and then run the test.

Hm, that sounds good, but I’m not sure I understand - would this only work for running individual tests? I’d need it to work with “Run All”.
(I’ll test it out)

re-thinking this approach, it will enter play mode only once and run all tests, so it does not achieve what you want.
Are you sure these settings cannot be modified during play mode ?