Skip to content

Conversation

@JasonXuDeveloper
Copy link
Owner

Summary

  • Fixed play mode test scene jumping issue that was causing test failures
  • Improved play mode test detection by preventing RuntimeInitializeOnLoadMethod registration during tests
  • Changed detection mechanism to use scene name checking instead of timing-dependent callbacks
  • Added Unity Test Framework temporary test scenes to .gitignore
  • Refactored test code to use simplified lambda expressions and improved code clarity

Changes

  • Modified ChangeScene.cs to detect play mode tests by checking scene name instead of callbacks
  • Added test scene patterns to .gitignore to prevent temporary test files from being tracked
  • Cleaned up JActionTests.cs and JActionRuntimeTests.cs:
    • Simplified lambda expressions by removing explicit parameter types
    • Added missing using statements
    • Removed redundant namespace prefixes
    • Changed DelayFrame(1) to DelayFrame() for default behavior

Test plan

  • Run all editor tests in Unity Test Runner
  • Run all play mode tests in Unity Test Runner
  • Verify no scene jumping during test execution
  • Verify .gitignore correctly excludes test scenes

🤖 Generated with Claude Code

JasonXuDeveloper and others added 5 commits January 22, 2026 15:59
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>
@JasonXuDeveloper JasonXuDeveloper enabled auto-merge (squash) January 22, 2026 05:32
@claude
Copy link

claude bot commented Jan 22, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@JasonXuDeveloper JasonXuDeveloper merged commit 6db9da5 into master Jan 22, 2026
5 checks passed
@JasonXuDeveloper JasonXuDeveloper deleted the fix/play-mode-tests branch January 22, 2026 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant