Fix play mode test issues and refactor test code#551
Merged
Conversation
This commit fixes an issue where play mode tests would jump to the init scene but not run any tests. Changes: - Wrap TestRunnerCallbacks.IsRunningTests check with #if UNITY_INCLUDE_TESTS in ChangeScene.cs This ensures the test runner check is only performed when test framework is available - Add test assembly reference to JEngine.Core.Editor.asmdef (GUID:0acc523941302664db1f4e527237feb3) - Update .gitignore to exclude Claude-generated files The root cause was that ChangeScene.cs was trying to check TestRunnerCallbacks.IsRunningTests without verifying the test framework was available, which could cause the check to fail or not work properly during play mode tests. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…dMethod registration The previous fix checked TestRunnerCallbacks.IsRunningTests at runtime, but there was a timing issue - RuntimeInitializeOnLoadMethod executes before TestRunnerCallbacks.RunStarted is called, so the flag was not set yet. This commit uses the cleaner approach recommended by Unity: prevent the method from being registered at all during tests by applying #if !UNITY_INCLUDE_TESTS to the attribute itself. This eliminates the runtime check and TestRunnerCallbacks dependency entirely from ChangeScene.cs, making the code simpler and more reliable. References: - Unity Discussions: RuntimeInitializeOnLoadMethod runs during playmode unit tests https://discussions.unity.com/t/methods-with-runtimeinitializeonloadmethod-attribute-run-during-playmode-unit-tests/949876 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…dent 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>
Unity Test Framework creates temporary scenes like InitTestScene<timestamp>.unity when running play mode tests. These should not be committed to the repository. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ode clarity - Simplified lambda expressions by removing explicit parameter types - Added missing using statements for System.Collections.Generic and System.Reflection - Removed redundant System namespace prefixes - Changed DelayFrame(1) to DelayFrame() for default behavior - Minor code cleanup for better readability Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
ChangeScene.csto detect play mode tests by checking scene name instead of callbacks.gitignoreto prevent temporary test files from being trackedTest plan
🤖 Generated with Claude Code