Testing Plan for Weapon Factory - UQcsse3200/2024-studio-1 GitHub Wiki
WeaponFactoryTest
Test Case 1: Create MeleeWeapon
Objective: Test that the WeaponFactory
can create a MeleeWeapon
.
Setup:
- Create an instance of
WeaponFactory
. - Use the
create
method withCollectible.Type.MELEE_WEAPON
and a valid melee weapon specification string.
Execution:
- Call the
create
method with a valid melee weapon specification.
Expected Outcome:
- The returned
Collectible
object is an instance ofMeleeWeapon
.
Test Case 2: Create RangedWeapon
Objective: Test that the WeaponFactory
can create a RangedWeapon
.
Setup:
- Create an instance of
WeaponFactory
. - Use the
create
method withCollectible.Type.RANGED_WEAPON
and a valid ranged weapon specification string.
Execution:
- Call the
create
method with a valid ranged weapon specification.
Expected Outcome:
- The returned
Collectible
object is an instance ofRangedWeapon
.
Test Case 3: Create Invalid MeleeWeapon
Objective: Validate that the WeaponFactory
throws an IllegalArgumentException
when an invalid melee weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory
.
Execution:
- Call the
create
method withCollectible.Type.MELEE_WEAPON
and an invalid melee weapon specification string.
Expected Outcome:
- An
IllegalArgumentException
is thrown.
Test Case 4: Create Invalid RangedWeapon
Objective: Validate that the WeaponFactory
throws an IllegalArgumentException
when an invalid ranged weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory
.
Execution:
- Call the
create
method withCollectible.Type.RANGED_WEAPON
and an invalid ranged weapon specification string.
Expected Outcome:
- An
IllegalArgumentException
is thrown.
Test Case 5: Create Invalid Weapon Type
Objective: Test that the WeaponFactory
throws an IllegalArgumentException
when an invalid weapon type is provided.
Setup:
- Create an instance of
WeaponFactory
.
Execution:
- Call the
create
method with an invalid weapon type (Collectible.Type.ITEM
) and a weapon specification string.
Expected Outcome:
- An
IllegalArgumentException
is thrown.
Test Case 6: Create Invalid Weapon Specification
Objective: Validate that the WeaponFactory
throws an IllegalArgumentException
when an invalid weapon specification is provided.
Setup:
- Create an instance of
WeaponFactory
.
Execution:
- Call the
create
method withCollectible.Type.RANGED_WEAPON
and an incorrectly formatted ranged weapon specification string.
Expected Outcome:
- An
IllegalArgumentException
is thrown.
Conlusion:
- This set of tests ensures that the WeaponFactory class is capable of creating valid melee and ranged weapons and correctly handles invalid inputs by throwing appropriate exceptions. The results will help improve the robustness and reliability of the weapon creation process within the game. The commented-out test cases for valid melee and ranged weapon creation should be included in future test executions to ensure full coverage.