SpeedBoostUpgrade - UQcsse3200/2024-studio-3 GitHub Wiki
Test Environment
- Framework: JUNIT 5
- Dependencies:
Mockito
: For mocking dependenciesParameterizedTest
: For testing different inputs
Test Cases
1. testSpeedBootsActivates
-
Purpose: To ensure that the speed boost upgrade activates correctly and the layout becomes visible.
-
Setup:
- Set player gold to a sufficient amount.
- Call activate() on the speedBootsUpgrade instance.
- Trigger the event Speed.
-
Expected Outcome:
- The upgrade should activate, and the layout and speedMeter should become visible.
- keyboardPlayerInputComponent should update the walking speed to the boosted value.
- The activeTimeRemaining should be set correctly.
- he event handler should trigger the event Speed.
2. testSpeedBootsDeactivates
- Purpose: To ensure that the speed boost upgrade deactivates correctly and the layout becomes hidden.
- Setup: Activate the speed boost, then call deactivate().
- Expected:
- The upgrade should deactivate, and the speedMeter and layout should be removed from the stage.
- keyboardPlayerInputComponent should update the walking speed to the normal value.
- The activeTimeRemaining should reset, and the event Speed should stop.
3. testLoseGoldOnPurchase
- Purpose: To ensure that the correct amount of gold is deducted when the upgrade is purchased.
- Setup:
- Set player gold to 100.
- Call activate() on the speedBootsUpgrade.
- Expected: The player's gold should decrease by 20 units upon activation.
4. testInsufficientGold
- Purpose: Ensure that the speed boost upgrade does not activate when there is insufficient gold.
- Setup:
- Set player gold to an insufficient amount (e.g., 10).
- Call activate() and verify that the event notenoughmoney is triggered.
- Expected:
- The upgrade should not activate, and the layout should remain hidden.
- The event handler should trigger notenoughmoney.
5. testSpeedBootsFor30Seconds
- Purpose: Ensure that the speed boost upgrade lasts for 30 seconds and deactivates after the time elapses.
- Setup: Activate the speed boots and simulate 30 seconds by calling update() repeatedly.
- Expected:
- The upgrade should deactivate after 30 seconds, and the speedMeter should deplete.
- The boost sound should stop playing after the boost expires.
6. testMeterValueAtDifferentLevelsOfDepletion
- Purpose: Ensure that the progress meter value updates correctly as time depletes.
- Setup:
- Use parameterized values for the total depleted time (5, 10, 15, 20, 25, 30 seconds).
- Activate the speed boots and simulate time by calling update() based on the given value.
- Expected: The speedMeter value should reflect the remaining boost time relative to the total duration.
7. testDispose
- Purpose: Ensure that all resources related to the speed boost upgrade are unloaded correctly when dispose() is called.
- Setup:
- Call dispose() on the speedBootsUpgrade instance.
- Verify that the resourceService.unloadAssets() method is called for the textures.
- Expected: The textures related to the speed boots should be unloaded from memory.