Testing Planning for Weapon Factory - UQcsse3200/2024-studio-1 GitHub Wiki

Objective

The purpose of this test plan is to validate the functionality of the WeaponFactory class within the game. This class is crucial as it manages the creation of different types of weapons and weapon entities. The tests aim to ensure that all functionalities such as weapon creation, entity creation, and error handling work as expected.

Test Environment

Framework: JUnit 5 (Jupiter)

Extensions:

  • MockitoExtension for mocking dependencies
  • GameExtension for handling game-specific components

Objects Used:

  • WeaponFactory class for creating weapons and weapon entities
  • Collectible class and its subclasses (MeleeWeapon, RangedWeapon)
  • Entity class representing game entities
  • Various service classes (RenderService, GameTime, EntityService, PhysicsService, ResourceService)

Setup:

  • The beforeEach() method initializes key components before each test case, ensuring a consistent and clean test environment.
  • Mock services are registered using ServiceLocator.
  • Resources are loaded, including projectile textures.
  • A new WeaponFactory instance is created for each test.

Test Cases

Test Case 1: Create Collectible Melee Weapon

Objective: Validate that a melee weapon collectible is created successfully.

Setup: Call weaponFactory.create with Collectible.Type.MELEE_WEAPON and "knife".

Expected Outcome: The returned collectible is an instance of MeleeWeapon.


Test Case 2: Create Collectible Ranged Weapon

Objective: Ensure that a ranged weapon collectible is created successfully.

Setup: Call weaponFactory.create with Collectible.Type.RANGED_WEAPON and "shotgun".

Expected Outcome: The returned collectible is an instance of RangedWeapon.


Test Case 3: Create Invalid Collectible

Objective: Verify that creating an invalid weapon throws an appropriate exception.

Setup: Attempt to create invalid melee and ranged weapons.

Expected Outcome: IllegalArgumentException is thrown with appropriate error messages.


Test Case 4: Create Weapon Entity

Objective: Validate that weapon entities are created correctly for both melee and ranged weapons.

Setup: Create weapon entities for a knife (melee) and a shotgun (ranged).

Expected Outcome: Non-null Entity instances are returned for both weapon types.


Test Case 5: Create Invalid Weapon Entity

Objective: Ensure that creating an entity with an invalid weapon specification throws an exception.

Setup: Attempt to create weapon entities with invalid weapon specifications.

Expected Outcome: IllegalArgumentException is thrown with appropriate error messages.


Test Case 6: Create Entity with Invalid Collectible

Objective: Verify that attempting to create an entity with a null collectible throws an exception.

Setup: Call createWeaponEntity with a null collectible.

Expected Outcome: IllegalArgumentException is thrown with the message "Invalid collectible".

Integration Testing

  1. Weapon Creation and Entity Association:

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

    • Ensure smooth transitions when switching between different weapon types (melee to ranged and vice versa).
  3. Weapon Interaction with Environment:

    • Verify that created weapons interact correctly with the game environment (e.g., collision detection, range limitations).
  4. Multiple Weapon Handling:

    • Test creation and management of multiple weapons in the player's inventory.
  5. Weapon Behavior in Combat:

    • Verify correct execution of weapon behaviors in combat scenarios:
      • Melee weapons: Check attack range and damage application.
      • Ranged weapons: Test projectile creation, movement, and impact.
  6. Resource Management:

    • Ensure proper loading and unloading of weapon resources (textures, sounds) during gameplay.

Playtesting

Focus on the following aspects:

  1. Weapon Feel:

    • Ensure that using different weapons feels satisfying and impactful.
    • Verify that weapon switching is smooth and responsive.
  2. Weapon Balance:

    • Check that different weapon types are balanced in terms of damage, range, and utility.
  3. Visual Feedback:

    • Assess the clarity of visual feedback when using weapons (e.g., hit effects, projectile visibility).
  4. Performance:

    • Evaluate any performance issues when multiple weapons are in use simultaneously.
  5. Weapon Variety:

    • Assess if the range of available weapons provides enough variety and strategic options.
  6. Edge Case Scenarios:

    • Test weapon behavior in various game situations (e.g., crowded environments, long-range engagements).

Potential User Testing

Consider the following methods and topics:

  1. Think-aloud Protocol:

    • Have users verbalize thoughts as they switch between and use different weapons.
  2. Questionnaires:

    • Ask about the intuitiveness of weapon selection and use.
    • Gather opinions on the visual and auditory feedback of different weapons.
  3. Interviews:

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

    • Get feedback on weapon responsiveness and satisfaction of use.
  5. Surveys:

    • Understand player preferences for different weapon types and attributes.
  6. User Experience (UX) Metrics:

    • Track engagement time with different weapons, frustration levels, and overall enjoyment related to weapon interactions.

Conclusion

This test plan provides comprehensive coverage of the WeaponFactory functionality, ensuring that weapon creation, entity association, and gameplay integration are correctly handled across different scenarios. The inclusion of integration testing, playtesting, and user testing ensures a thorough evaluation of the weapon system from both technical and user experience perspectives.