Testing Plan for Weapon Component - UQcsse3200/2024-studio-1 GitHub Wiki

Objective

The purpose of this test plan is to validate the functionality of the WeaponComponent class within the game. This class is crucial as it manages the attributes and behavior of weapons in the game. The tests aim to ensure that all functionalities such as weapon creation, attribute handling, and error management work as expected.

Test Environment

Framework: JUnit 4

Extensions: GameExtension for handling libGDX components

Objects Used:

  • WeaponComponent class representing the weapon.
  • Sprite class for the weapon's visual representation.
  • Collectible.Type enum representing the weapon type (e.g., MELEE_WEAPON, RANGED_WEAPON).

Setup:

  • The setUp() method initializes key components before each test case, ensuring a consistent and clean test environment.

  • Weapon Component (weaponComponent): A new WeaponComponent instance is created with various attributes including sprite, weapon type, damage, range, fire rate, ammo, max ammo, and reload time.

Test Cases

Test Case 1: Weapon Component Creation

Objective: Validate that the WeaponComponent is created successfully.

Setup: Create a WeaponComponent with specified attributes.

Expected Outcome: weaponComponent is not null.


Test Case 2: Weapon Component Default Creation

Objective: Ensure that a WeaponComponent can be created with default (null or zero) values.

Setup: Create a WeaponComponent with all default values.

Expected Outcome: weaponComponent is not null.


Test Case 3: Weapon Damage Attribute

Objective: Verify that the damage attribute of the WeaponComponent is set and retrieved correctly.

Setup: Create a WeaponComponent with a specified damage value.

Expected Outcome: getDamage() returns the correct damage value.


Test Case 4: Weapon Range Attribute

Objective: Validate that the range attribute of the WeaponComponent is correctly set and retrieved.

Setup: Create a WeaponComponent with a specified range value.

Expected Outcome: getRange() returns the correct range value.


Test Case 5: Weapon Fire Rate Attribute

Objective: Ensure that the fire rate attribute of the WeaponComponent is set and retrieved correctly.

Setup: Create a WeaponComponent with a specified fire rate value.

Expected Outcome: getFireRate() returns the correct fire rate value.


Test Case 6: Weapon Ammo Attribute

Objective: Verify that the ammo attribute is correctly managed.

Setup: Create a WeaponComponent with a specified ammo value.

Expected Outcome: getAmmo() returns the correct ammo value.


Test Case 7: Weapon Max Ammo Attribute

Objective: Validate that the max ammo attribute is correctly set and retrieved.

Setup: Create a WeaponComponent with a specified max ammo value.

Expected Outcome: getMaxAmmo() returns the correct max ammo value.


Test Case 8: Weapon Reload Time Attribute

Objective: Ensure that the reload time attribute of the WeaponComponent is set and retrieved correctly.

Setup: Create a WeaponComponent with a specified reload time value.

Expected Outcome: getReloadTime() returns the correct reload time value.


Test Case 9: Weapon Type Attribute

Objective: Verify that the weapon type is correctly set and retrieved.

Setup: Create a WeaponComponent with a specified weapon type.

Expected Outcome: getWeaponType() returns the correct weapon type.


Test Case 10: Setting Weapon Type

Objective: Validate that the weapon type can be updated after creation.

Setup: Create a WeaponComponent and then set the weapon type to a different value.

Expected Outcome: getWeaponType() returns the updated weapon type.


Test Case 11: Handling Null Weapon Type

Objective: Ensure that the WeaponComponent correctly handles setting the weapon type to null.

Setup: Create a WeaponComponent and set its weapon type to null.

Expected Outcome: getWeaponType() returns null.


Test Case 12: Weapon Sprite Attribute

Objective: Validate that the sprite associated with the weapon is correctly set and retrieved.

Setup: Create a WeaponComponent with a specified sprite.

Expected Outcome: getWeaponSprite() returns the correct sprite.


Test Case 13: Handling Null Sprite

Objective: Ensure that the WeaponComponent can handle a null sprite value.

Setup: Create a WeaponComponent with a null sprite.

Expected Outcome: getWeaponSprite() returns null.


Test Case 14: Setting Weapon Sprite

Objective: Verify that the sprite of the WeaponComponent can be updated after creation.

Setup: Create a WeaponComponent and then set its sprite to a new value.

Expected Outcome: getWeaponSprite() returns the updated sprite.


Test Case 15: Setting Damage Attribute

Objective: Validate that the damage attribute of the WeaponComponent can be updated correctly.

Setup: Create a WeaponComponent and update its damage value.

Expected Outcome: getDamage() returns the updated damage value.


Test Case 16: Setting Range Attribute

Objective: Ensure that the range attribute can be updated correctly.

Setup: Create a WeaponComponent and update its range value.

Expected Outcome: getRange() returns the updated range value.


Test Case 17: Setting Fire Rate Attribute

Objective: Verify that the fire rate attribute can be updated correctly.

Setup: Create a WeaponComponent and update its fire rate value.

Expected Outcome: getFireRate() returns the updated fire rate value.


Test Case 18: Setting Ammo Attribute

Objective: Ensure that the ammo attribute can be updated correctly.

Setup: Create a WeaponComponent and update its ammo value.

Expected Outcome: getAmmo() returns the updated ammo value.


Test Case 19: Setting Ammo to Negative Value

Objective: Validate that the WeaponComponent correctly handles setting ammo to a negative value.

Setup: Create a WeaponComponent and set its ammo to -1 and -2.

Expected Outcome: Ammo is decreased by 1 for -1, or set to max ammo for -2.


Test Case 20: Setting Max Ammo Attribute

Objective: Ensure that the max ammo attribute can be updated correctly.

Setup: Create a WeaponComponent and update its max ammo value.

Expected Outcome: getMaxAmmo() returns the updated max ammo value.


Test Case 21: Setting Reload Time

Objective: Verify that the reload time attribute can be updated correctly.

Setup: Create a WeaponComponent and update its reload time value.

Expected Outcome: getReloadTime() returns the updated reload time value.


Test Case 22: Handling Negative Reload Time

Objective: Ensure that the WeaponComponent correctly handles setting reload time to a negative value.

Setup: Create a WeaponComponent and set its reload time to a negative value.

Expected Outcome: An IllegalArgumentException is thrown with the correct message.


Test Case 23: Setting Reload Time to Zero

Objective: Validate that the WeaponComponent can handle a reload time of zero.

Setup: Create a WeaponComponent and set its reload time to zero.

Expected Outcome: getReloadTime() returns zero.


Test Case 24: Setting Reload Time to Max Value

Objective: Ensure that the WeaponComponent can handle the maximum possible reload time value.

Setup: Create a WeaponComponent and set its reload time to Integer.MAX_VALUE.

Expected Outcome: getReloadTime() returns Integer.MAX_VALUE.


Integration Testing

  1. Weapon-Entity Integration:

    • Test the complete lifecycle of a weapon from creation to association with a player entity.
    • Verify that weapon attributes are correctly applied when the weapon is equipped by a player.
  2. Weapon Switching:

    • Ensure smooth transitions when switching between different weapons.
    • Verify that weapon attributes are updated correctly during switches.
  3. Combat System Integration:

    • Test how the WeaponComponent interacts with the game's combat system.
    • Verify damage calculation, range detection, and ammo management during combat scenarios.
  4. UI Integration:

    • Ensure that weapon information is correctly displayed in the game's UI.
    • Test UI updates when weapon attributes change (e.g., ammo count, reload status).
  5. Physics System Integration:

    • Verify correct interaction between weapon range and the game's physics system.
    • Test projectile creation and movement for ranged weapons.
  6. Audio System Integration:

    • Ensure that appropriate sound effects are triggered for weapon actions (firing, reloading, etc.).

Playtesting

Focus on the following aspects:

  1. Weapon Feel:

    • Ensure that using different weapons feels satisfying and impactful.
    • Verify that weapon attributes (damage, range, fire rate) feel balanced and appropriate.
  2. Weapon Variety:

    • Assess if the range of available weapons provides enough variety and strategic options.
  3. Ammo Management:

    • Check if ammo management feels challenging but fair.
    • Evaluate the balance of ammo availability in the game.
  4. Reload Mechanics:

    • Ensure that reload times feel appropriate for each weapon type.
    • Verify that reload animations (if present) are smooth and satisfying.
  5. Weapon Switching:

    • Assess the fluidity and responsiveness of weapon switching during gameplay.
  6. Edge Case Scenarios:

    • Test weapon behavior in various game situations (e.g., low ammo, rapid switching, environmental interactions).

Potential User Testing

Consider the following methods and topics:

  1. Think-aloud Protocol:

    • Have users verbalize thoughts as they use different weapons and manage their attributes.
  2. Questionnaires:

    • Ask about the intuitiveness of weapon mechanics and attribute management.
    • Gather opinions on the balance and feel of different weapon types.
  3. Interviews:

    • Conduct post-play interviews for detailed feedback on weapon mechanics and overall combat experience.
  4. Direct Player Feedback:

    • Get feedback on weapon responsiveness, visual and audio feedback, and overall satisfaction.
  5. Surveys:

    • Understand player preferences for different weapon types and attributes.
    • Assess player perception of weapon balance and variety.
  6. User Experience (UX) Metrics:

    • Track engagement time with different weapons, frustration levels with ammo/reload mechanics, and overall enjoyment related to weapon interactions.
  7. A/B Testing:

    • Test different configurations of weapon attributes (e.g., varying reload times or damage values) to find the most satisfying balance.

Conclusion

This expanded test plan provides comprehensive coverage of the WeaponComponent functionality, ensuring that all key attributes are correctly handled, initialized, and modified across different scenarios. The addition of integration testing, playtesting, and user testing ensures a thorough evaluation of the weapon system from both technical and user experience perspectives. This approach will help identify any issues with the component's implementation and its impact on overall gameplay, allowing for refinement and optimization of the weapon mechanics to create a more enjoyable and balanced gaming experience.