Skip to content

Instantly share code, notes, and snippets.

@adammyhre
Created January 21, 2024 07:18
Show Gist options
  • Save adammyhre/20d3c47f83032c6ca938b92edc175a35 to your computer and use it in GitHub Desktop.
Save adammyhre/20d3c47f83032c6ca938b92edc175a35 to your computer and use it in GitHub Desktop.
Unity Testing LoadSceneAttribute
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