I'm trying to set up a system where each unit test is a separate scene. To load a scene at runtime, I need to add them to `EditorBuildSetting.scene`. I currently do this by using the [PrebuildSetup](https://docs.unity3d.com/ScriptReference/TestTools.PrebuildSetupAttribute.html) attribute.
This works fine, however I would like to reset the original build settings after the unit tests were completed. I tried using the PostBuildSetup attribute to implement a Cleanup method that resets the build settings scenes to the original list, but between the setup and the cleanup functions, the list I store becomes null:
[PrebuildSetup(typeof(RenderPerformancePrebuildSetup))]
[PostBuildCleanup(typeof(RenderPerformancePostBuildCleanup))]
public class RenderPerformanceTests
{
[PerformanceTest]
public void SimplePerformanceTest()
{
// do stuff
}
}
public class RenderPerformancePrebuildSetup : IPrebuildSetup
{
public static Scene[] buildSettingsScenes;
public void Setup()
{
buildSettingsScenes = EditorBuildSettings.scenes;
EditorBuildSettings.scenes = // list of test scenes;
}
}
public class RenderPerformancePostBuildCleanup : IPostBuildCleanup
{
public void Cleanup()
{
EditorBuildSettings.scenes = RenderPerformancePrebuildSetup.buildSettingsScenes;
}
}
↧