Hey all:
I’m writing a utility library that makes heavy use of ScriptableObjects, which as we all know have persistent state across Play and Edit modes … however, I want certain variables to revert back to their initial values after leaving Play mode, even if they’re stored in SO’s. (Long story – don’t ask.) To that end, I’m writing a number of unit tests that have the following form:
[UnityTest]
public IEnumerator FooRevertsToInitialAfterQuit()
{
// set up initial value(s) here
yield return new EnterPlayMode();
// change to runtime value(s) here
yield return new ExitPlayMode();
// assert that Foo goes back to returning the initial value
}
The problem (annoyance, really) I’m facing is that the Editor changes focus to the Game window when I execute that “yield return new EnterPlayMode();” line, and does NOT change back when the tests are all complete. I’d really like to do something like was discussed here , but instead of auto-switching back to the scene view, I’d like to automatically switch back to the Test Runner window.
It seems like it’s just a matter of passing in the correct Type argument to UnityEditor.SceneView.FocusWindowIfItsOpen() … but I can’t find the C# type of the Test Runner window! Google keeps giving me irrelevant results.
Any thoughts? Also, if you think I’m wildly off-base with that test pattern, I’m open to alternatives.
(Aside: I just tried posting this with the Answers “Ask a Question” form, but either I’m failing an IQ test or the form is bugged on my browser. When I tried to enter a topic, no results were found, even for single-character strings … and it wouldn’t let me enter a new topic. Then it complained that I NEEDED a topic to post!)