Testing Plan for ConcreteMeleeWeapon component - UQcsse3200/2024-studio-1 GitHub Wiki
Test Plan for ConcreteMeleeWeapon component
Objective
The objective of this test plan is to validate the functionality of the ConcreteMeleeWeapon class, ensuring correct behavior for creating melee weapons, managing weapon entities, handling pickups and drops in inventory, and verifying weapon attributes like name, icon, damage, range, and fire rate.
Test Environment
Framework: JUnit 5 with Mockito for mocking dependencies
Objects Used:
ConcreteMeleeWeapon: Represents a concrete implementation of a melee weapon.Entity: Represents game entities like players or weapons.InventoryComponent: Manages the player's inventory.FiringController: Handles firing logic for the weapon (added to weapon entities).WeaponFactory: Factory class for creating weapon objects (mocked).Inventory: A class representing the player's inventory system.
Setup:
- The
beforeEach()method registers the required services (RenderService,EntityService,PhysicsService, andResourceService) and loads projectile textures. - Mocks are created for
Entity(for the weapon entity) andConcreteMeleeWeapon.
Test Cases
Test Case 1: Create Collectible Melee Weapon
Objective: Verify that a ConcreteMeleeWeapon instance is successfully created.
Setup: Instantiate a new ConcreteMeleeWeapon with parameters: name, icon path, damage, range, and fire rate.
Expected Outcome:
- The instance is successfully created and is a type of
MeleeWeapon.
Test Case 2: Set Weapon Entity
Objective: Test the functionality of assigning a weapon entity to the ConcreteMeleeWeapon.
Setup:
- Create a
ConcreteMeleeWeaponinstance. - Create a new
Entityrepresenting the weapon entity. - Use the
setWeaponEntity()method to assign the entity to the melee weapon.
Expected Outcome:
- The
getWeaponEntity()method should return the assigned entity.
Test Case 3: Pickup Weapon
Objective: Ensure that the melee weapon can be picked up and added to the player's inventory.
Setup:
- Create a
ConcreteMeleeWeaponinstance and set a weapon entity. - Create an
InventoryComponentand add it to a player entity. - Create an
Inventoryobject and callpickup()with the inventory.
Expected Outcome:
- The weapon should be added to the player's inventory, and
inventory.getMelee().isPresent()should returntrue.
Test Case 4: Drop Weapon
Objective: Ensure that the melee weapon can be dropped and removed from the player's inventory.
Setup:
- Create a
ConcreteMeleeWeaponinstance and set a weapon entity. - Create an
InventoryComponentand add it to a player entity. - Create an
Inventoryobject, callpickup()to add the weapon to the inventory, and then calldrop().
Expected Outcome:
- The weapon should be removed from the inventory, and
inventory.getMelee().isPresent()should returnfalse.
Test Case 5: Get Weapon Specification
Objective: Validate the weapon specification string returned by the getSpecification() method.
Setup:
- Create a
ConcreteMeleeWeaponinstance with the name "knife". - Call
getSpecification().
Expected Outcome:
- The result should be
"melee:knife".
Test Case 6: Get Weapon Name
Objective: Ensure the weapon's name is correctly retrieved using the getName() method.
Setup:
- Create a
ConcreteMeleeWeaponinstance with the name "knife". - Call
getName().
Expected Outcome:
- The result should be
"knife".
Test Case 7: Get Icon Path
Objective: Validate that the weapon's icon path is correctly retrieved.
Setup:
- Create a
ConcreteMeleeWeaponinstance with the icon path "knife.png". - Call the
iconPathattribute directly.
Expected Outcome:
- The result should be
"knife.png".
Test Case 8: Getters for Weapon Attributes
Objective: Verify that the weapon's damage, range, and fire rate can be retrieved correctly.
Setup:
- Create a
ConcreteMeleeWeaponinstance with values10for damage, range, and fire rate. - Call
getDamage(),getRange(), andgetFireRate().
Expected Outcome:
- The results should be
10for all three attributes.
Test Case 9: Setters for Weapon Attributes
Objective: Ensure that the weapon's damage, range, and fire rate can be modified correctly using setter methods.
Setup:
- Create a
ConcreteMeleeWeaponinstance with initial values. - Use
setDamage(),setRange(), andsetFireRate()to change the values to20. - Call the respective getter methods to verify the changes.
Expected Outcome:
- The values should be updated to
20for damage, range, and fire rate.
Test Case 10: Weapon Attack
Objective: Validate that the weapon can successfully perform an attack and remain present in the player's inventory.
Setup:
- Create a
ConcreteMeleeWeaponinstance and set a weapon entity. - Create an
InventoryComponentand add it to a player entity. - Call
pickup()to add the weapon to the inventory, and then callattack().
Expected Outcome:
- The weapon should remain in the inventory after the attack, and
inventory.getMelee().isPresent()should returntrue.
Conclusion
This test plan ensures that the ConcreteMeleeWeapon class performs as expected in creating weapons, managing weapon entities, interacting with the player's inventory, and verifying key weapon attributes such as damage, range, and fire rate.