Test Plan for Saving Character State - UQcsse3200/2024-studio-1 GitHub Wiki
Objective
The purpose of this test plans to valid the functionality of saving character into a json file, specifically PlayerConfigGenerator class within the game as this class converts player's components into a writeable file.
Test Environment
- FrameWork: JUnit4
- Extensions:
GameExtensionfor handling libGDX components - Objects Used:
Entityclass representing the player,InventoryComponentandCombatStatsComponentrepresenting the player's inventory and combat stats.PlayerConfigGeneratorclass under test.
SetUp() Method
The setUp() method initializes key components before each test case, ensuring a consistent and clean test environment.
- Player Entity (
player): A newEntityinstance is created, representing the player. - InventoryComponent (
inventoryComponent): Manages the player's inventory, crucial for testing item and weapon saving. - CombatStatsComponent (
statsComponent): Stores the player's health and attack stats, initialized with default values.
Test Cases
1. Test Case 1: Initialization with Default Player Attributes
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves the player's state. - Setup:
- A player entity is created with an
InventoryComponentandCombatStatsComponent(health = 100, attack = 30).
- A player entity is created with an
- Expected Outcome:
- baseAttack is 30.
- health is 100.
- The items array is empty.
2. Test Case 2: Customized Combat Stats
- Objective: Ensure that the
PlayerConfigGeneratorcorrectly saves custom combat stats. - Setup:
- Player's combat stats are customized (health = 50, attack = 20).
- Expected Outcome:
- baseAttack is 20.
- health is 50.
3. Test Case 3: Melee Weapon Equipped
- Objective: Verify that the
PlayerConfigGeneratorcorrectly saves the equipped melee weapon. - Setup:
- A melee weaponis equipped.
- the specification of melee weapon is customised as it has not been implemented by weapons team yet.
- Expected Outcome:
- The melee attribute in
PlayerConfigis set to "melee:".
- The melee attribute in
4. Test Case 4: Ranged Weapon Equipped
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves the equipped ranged weapon. - Setup:
- A ranged weapon is equipped.
- the specification of melee weapon is customised as it has not been implemented by weapons team yet.
- Expected Outcome:
- The ranged attribute in
PlayerConfigis set to "ranged:".
- The ranged attribute in
5. Test Case 5: No Weapons Equipped
- Objective: Ensure that
PlayerConfigGeneratorcorrectly handles cases where no weapons are equipped. - Setup:
- No weapons are equipped.
- Expected Outcome:
- Both ranged and melee attributes in
PlayerConfigare empty strings.
- Both ranged and melee attributes in
6. Test Case 6: Single Item in Inventory
- Objective: Confirm that the
PlayerConfigGeneratorcorrectly saves a single item in the player's inventory. - Setup:
- A single item (Health Potion) is added to the inventory.
- Expected Outcome:
- items array contains one string element: "Health Potion".
7. Test Case 7: Multiple Items in Inventory
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves multiple items in the player's inventory. - Setup:
- Multiple items (Energy bar, Food) are added to the inventory.
- Expected Outcome:
- items array contains two elements: ["Energy bar", "Food”].
8. Test Case 3: Saving Player Coins
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves the player's coins. - Setup: Player is assigned 10 coins.
- Expected Outcome:
coinsis 10.
9. Test Case 4: Saving Player Speed
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves the player's speed. - Setup: Player's speed is set to
Vector2(5f, 5f). - Expected Outcome:
speedisVector2(5f, 5f).
10. Test Case 8: Player with No Inventory Items
- Objective: Ensure that the items array remains empty if the player has not collected any items.
- Setup: Player has no items in their inventory.
- Expected Outcome:
items.lengthis 0.
11. Test Case 11: Player's Max Health
- Objective: Validate that the player's max health is saved correctly.
- Setup: Player's max health is set to 120.
- Expected Outcome:
maxHealthis 120.
12. Test Case 12: Saving Armor and Buffs
- Objective: Ensure that player's armor and buffs are saved correctly.
- Setup: Player picks up an armor item and a damage buff.
- Expected Outcome:
armoris 20.buffis 15.0f.
13. Test Case 13: Saving Critical Stats
- Objective: Ensure that the player's critical stats are saved correctly.
- Setup: Player has a critical chance of 5% and is able to perform critical hits.
- Expected Outcome:
critChanceis 5%.canCritistrue.
14. Test Case 14: Saving Pets
- Objective: Validate that the player's pets are saved correctly.
- Setup: Player collects a pet ("dragon").
- Expected Outcome:
pets[0]is "pet:dragon".pets.lengthis 1.
15. Test Case 15: Multiple Pets
- Objective: Ensure that multiple pets are saved correctly.
- Setup: Player collects two pets ("Dragon", "Wolf").
- Expected Outcome:
petsarray contains "Dragon", "Wolf".pets.lengthis 2.
16. Test Case 16: Player with No Coins
- Objective: Ensure that player's coin count is saved correctly when the player has no coins.
- Setup: Player has 0 coins.
- Expected Outcome:
coinsis 0.
17. Test Case 17: Player with Empty Inventory and No Pets
- Objective: Validate that the
PlayerConfigGeneratorcorrectly saves a player with no items or pets. - Setup: Player has no items and no pets.
- Expected Outcome:
items.lengthis 0.pets.lengthis 0.
Execution
Tests were be executed using the JUnit framework within the development environment, ensuring that each test case passes independently, confirming the integrity and correctness of the PlayerConfigGenerator class.
Conclusion
This test plan provides comprehensive coverage of the PlayerConfigGenerator functionality, ensuring that player states are correctly captured and saved across different scenario