Skip to content

Commit 08636db

Browse files
Address code review feedback for TestRunnerCallbacks
- Fix doc comment: "Play Mode tests" -> "tests" (ICallbacks tracks both modes) - Add proper cleanup: store TestRunnerApi as static field, unregister and destroy on EditorApplication.quitting to prevent memory leaks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ef184d7 commit 08636db

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

UnityProject/Packages/com.jasonxudeveloper.jengine.core/Editor/Misc/TestRunnerCallbacks.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,30 @@ namespace JEngine.Core.Editor.Misc
1111
internal class TestRunnerCallbacks : ICallbacks
1212
{
1313
/// <summary>
14-
/// Returns true when Play Mode tests are currently running
14+
/// Returns true when tests are currently running
1515
/// </summary>
1616
public static bool IsRunningTests { get; private set; }
1717

18+
private static readonly TestRunnerCallbacks _instance = new TestRunnerCallbacks();
19+
private static TestRunnerApi _api;
20+
1821
static TestRunnerCallbacks()
1922
{
20-
var api = ScriptableObject.CreateInstance<TestRunnerApi>();
21-
api.RegisterCallbacks(new TestRunnerCallbacks());
23+
_api = ScriptableObject.CreateInstance<TestRunnerApi>();
24+
_api.RegisterCallbacks(_instance);
25+
EditorApplication.quitting += OnEditorQuitting;
26+
}
27+
28+
private static void OnEditorQuitting()
29+
{
30+
EditorApplication.quitting -= OnEditorQuitting;
31+
32+
if (_api != null)
33+
{
34+
_api.UnregisterCallbacks(_instance);
35+
ScriptableObject.DestroyImmediate(_api);
36+
_api = null;
37+
}
2238
}
2339

2440
public void RunStarted(ITestAdaptor testsToRun)

0 commit comments

Comments
 (0)