Commit 6b011e9
Detect play mode tests by checking scene name instead of timing-dependent callbacks
The previous approaches had timing issues - TestRunnerCallbacks.RunStarted is called
after RuntimeInitializeOnLoadMethod, and #if !UNITY_INCLUDE_TESTS doesn't work because
the assembly always has UNITY_INCLUDE_TESTS defined (it contains test files).
This commit uses a simple, reliable approach: Unity Test Framework creates temporary
scenes with names like "InitTestScene<timestamp>" when running play mode tests. By
checking if the current scene name starts with "InitTestScene", we can reliably detect
test runs at runtime without timing dependencies.
Benefits:
- No timing issues with callbacks
- No dependency on preprocessor directives
- Works in all scenarios (GUI test runner, command line, etc.)
- Simple and maintainable
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 7aa10e2 commit 6b011e9
1 file changed
Lines changed: 9 additions & 3 deletions
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | 12 | | |
15 | | - | |
16 | 13 | | |
17 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | 26 | | |
| |||
0 commit comments