Created
January 21, 2024 07:18
-
-
Save adammyhre/20d3c47f83032c6ca938b92edc175a35 to your computer and use it in GitHub Desktop.
Unity Testing LoadSceneAttribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoadSceneAttribute : NUnitAttribute, IOuterUnityTestAction { | |
readonly string scene; | |
public LoadSceneAttribute(string scene) => this.scene = scene; | |
public IEnumerator BeforeTest(ITest test) { | |
Debug.Assert(scene.EndsWith(".unity"), "Scene must end with .unity"); | |
yield return EditorSceneManager.LoadSceneInPlayMode(scene, new LoadSceneParameters(LoadSceneMode.Single)); | |
} | |
public IEnumerator AfterTest(ITest test) { | |
yield return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment