fix: normalize test harness style#197
Merged
Merged
Conversation
- Replace extends TestSuite with extends SceneTree in test_food_upkeep.gd
- Remove stale Globals.get_node("/root/Main") calls in test_resource_trends.gd (9 occurrences replaced with load()+new() instantiation)
- Rewrite test_food_upkeep.gd to call actual Main methods instead of static helpers that mirrored implementation without importing it
- Add harness helpers (_assert, _assert_eq, etc.) matching test_runner pattern
There was a problem hiding this comment.
AI Automated Review
Full PR review.
Analysis engine: review@https://litellm.jory.dev/v1 (openai)
Recommendation
Approved. This PR successfully addresses the technical debt identified in issue PR 182 by normalizing the test harness style across the repository.
Change-by-Change Findings
tests/test_food_upkeep.gd
- Harness Update: Changed
extends TestSuitetoextends SceneTreeto avoid stale references. - Implementation Change: Replaced static helper functions (which mirrored implementation logic) with direct instantiation of
Mainviaload("res://scripts/main.gd").new(). This ensures tests validate the actual game logic rather than a mock. - State Management: Tests now explicitly set
main.statebefore execution, ensuring isolation and predictable test conditions. - Assertion Style: Introduced internal harness helpers (
_assert,_assert_eq,_assert_lt, etc.) to match the pattern used in the repository'stest_runner.gd. - Reporting: Added a summary output at the end of the test execution to report pass/fail counts.
tests/test_resource_trends.gd
- Harness Update: Removed all
Globals.get_node("/root/Main")calls, which relied on theMainsingleton being present in the scene tree. - Implementation Change: Standardized on loading
res://scripts/main.gdand instantiating a freshMaininstance for every test case, ensuring true unit testing of the trend logic without side effects from a global singleton.
Linked Issue Fit
This PR directly satisfies the requirements of PR 182 (Normalize generated test style):
- One harness pattern: All tests now use
SceneTreeand a consistent_initializepattern. - No stale
Globals/TestSuitereferences: RemovedTestSuiteinheritance andGlobals.get_nodecalls. - No tests mirroring implementation: Replaced static mocks with actual
Mainmethod calls on instantiated objects.
Standards Compliance
- Repository Conventions: The implementation follows the established pattern of using
SceneTreefor headless tests and matches the assertion style found intests/test_runner.gdand other existing test files. - Consistency: The use of
load().new()for test isolation is consistent with the patterns seen intests/test_dirty_state_tracking.gdandtests/test_colony_stance.gd.
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.
Fixes #182
extends TestSuitewithextends SceneTreein test_food_upkeep.gd (stale reference)Globals.get_node("/root/Main")calls in test_resource_trends.gd (9 occurrences replaced withload()+new()instantiation)_assert,_assert_eq, etc.) matching the test_runner pattern