Test Plan for FiringController - UQcsse3200/2024-studio-1 GitHub Wiki
Test Plan for FiringController Class
Objective
The purpose of this test plan is to validate the functionality of the FiringController class. This class is responsible for handling both melee and ranged weapon attacks in the game. The tests aim to ensure the correct behavior for creating controllers, connecting players, activating attacks, and managing weapon attributes like damage, range, and ammo.
Test Environment
Framework: JUnit 5 with Mockito for mocking dependencies
Objects Used:
FiringControllerfor controlling the firing mechanism of weapons.MeleeWeaponandRangedWeaponclasses representing melee and ranged weapons.Entityclass to represent the player or other entities.ProjectileConfigfor managing projectiles used by ranged weapons.WeaponFactoryfor creating weapon objects.
Setup:
- The
beforeEach()method registers necessary services likeRenderService,EntityService,PhysicsService, andResourceServiceand ensures assets are loaded. - Mocks are created for classes such as
WeaponFactoryandGameTimeto simulate in-game conditions.
Test Cases
Test Case 1: FiringController Creation for Melee Weapon
Objective: Verify that a FiringController can be created for a melee weapon.
Setup: Create a MeleeWeapon collectible and pass it to a new FiringController instance.
Expected Outcome:
- The
FiringControlleris successfully created. - The instance of
FiringControlleris not null.
Test Case 2: FiringController Creation for Ranged Weapon
Objective: Validate that a FiringController can be created for a ranged weapon.
Setup: Create a RangedWeapon collectible and pass it to a new FiringController instance along with a ProjectileConfig.
Expected Outcome:
- The
FiringControlleris successfully created. - A
ProjectileFactoryinstance is initialized. - The
ProjectileFactoryis not null.
Test Case 3: Connect and Disconnect Player
Objective: Test the ability to connect and disconnect a player entity to/from the FiringController.
Setup: Create a player Entity, connect it to the FiringController, and then disconnect it.
Expected Outcome:
- Player is correctly connected to the
FiringController. - The target layer is set to
PhysicsLayer.NPC. - After disconnecting, the player is set to null.
Test Case 4: Activate Ranged Weapon
Objective: Ensure that activating the ranged weapon triggers the correct action and handles different cases.
Setup: Connect a player entity to the FiringController and call activate() with and without a direction.
Expected Outcome:
- When direction is provided, "Ranged weapon attack triggered" is returned.
- When direction is not provided, "No direction specified for ranged weapon" is returned.
Test Case 5: Activate Melee Weapon
Objective: Validate the activation of melee weapons.
Setup: Create a MeleeWeapon, pass it to the FiringController, and call activate() with and without a direction.
Expected Outcome:
- "Melee weapon attack triggered" is returned in both cases (direction specified or not).
Test Case 6: Setters and Getters for Melee Weapon
Objective: Ensure correct functionality of setters and getters for melee weapon attributes.
Setup: Use a MeleeWeapon and check values for damage, range, and fire rate. Update them using the setter methods.
Expected Outcome:
- Damage, range, and fire rate are correctly set and retrieved.
ReloadTime,MaxAmmo, andAmmoremain unaffected as they are not applicable to melee weapons.- Weapon sprite is correctly set and retrieved.
Test Case 7: Setters and Getters for Ranged Weapon
Objective: Validate the setters and getters for ranged weapon attributes.
Setup: Use a RangedWeapon and check values for damage, range, fire rate, reload time, ammo, and max ammo. Update them using the setter methods.
Expected Outcome:
- Damage, range, fire rate, reload time, ammo, and max ammo are correctly set and retrieved.
- Weapon sprite is correctly set and retrieved.
Conclusion
This test plan ensures that the FiringController class behaves as expected when managing melee and ranged weapons. The test cases cover the creation of the controller, handling player connections, activating weapon attacks, and verifying the correct management of weapon attributes.