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:

  • FiringController for controlling the firing mechanism of weapons.
  • MeleeWeapon and RangedWeapon classes representing melee and ranged weapons.
  • Entity class to represent the player or other entities.
  • ProjectileConfig for managing projectiles used by ranged weapons.
  • WeaponFactory for creating weapon objects.

Setup:

  • The beforeEach() method registers necessary services like RenderService, EntityService, PhysicsService, and ResourceService and ensures assets are loaded.
  • Mocks are created for classes such as WeaponFactory and GameTime to 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 FiringController is successfully created.
  • The instance of FiringController is 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 FiringController is successfully created.
  • A ProjectileFactory instance is initialized.
  • The ProjectileFactory is 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, and Ammo remain 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.