Skip to content

Powerups Testing Plan

Kushagra Agrawal edited this page Oct 18, 2023 · 4 revisions

Introduction:

Powerups play a significant role in the game dynamics and must be tested thoroughly; therefore, PowerupFactory and PowerupComponent have been tested in accordance with the following testing plan:

Test Plan for PowerupFactory

Objective:

To validate the correct creation and behaviour of powerup entities by the PowerupFactory ensuring:

  • Powerup entities are successfully created and are not null.
  • Powerup entities created have the expected type, whether a health boost, speed boost or extra life.

Methodology:

Setup (BeforeEach):

  • Initialize necessary services and resources needed for testing using ServiceLocator.
  • Register the EntityService and PhysicsService using the ServiceLocator.
  • Create a new ResourceService instance and load powerup textures (health, speed and extra life) from specified paths.

Test Case 1: testCreateHealthPowerup

Objective: To verify the creation of a health powerup entity.

Steps:

  • Use PowerupFactory to create a health powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is HEALTH_BOOST.

Test Case 2: testCreateSpeedPowerup

Objective: To verify the creation of a speed powerup entity.

Steps:

  • Use PowerupFactory to create a speed powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is SPEED_BOOST.

Test Case 3: testCreateExtraLifePowerup

Objective: To verify the creation of an extra life powerup entity.

Steps:

  • Use PowerupFactory to create an extra life powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is EXTRA_LIFE.

Test Case 4: testCreateDoubleCrossPowerup

Objective: To verify the creation of a double cross powerup entity.

Steps:

  • Use PowerupFactory to create a double cross powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is DOUBLE_CROSS.

Test Case 5: testCreateDoubleDamagePowerup

Objective: To verify the creation of a double damage powerup entity.

Steps:

  • Use PowerupFactory to create a double damage powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is DOUBLE_DAMAGE.

Test Case 6: testCreateSnapPowerup

Objective: To verify the creation of a snap powerup entity.

Steps:

  • Use PowerupFactory to create a snap powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is SNAP.

Test Case 7: testCreateTempImmunityPowerup

Objective: To verify the creation of an immunity powerup entity.

Steps:

  • Use PowerupFactory to create an immunity powerup entity.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is TEMP_IMMUNITY.

Test Case 8: createHealthPowerupConfigTest

Objective: To verify the creation of a health powerup config.

Steps:

  • Use PowerupConfig to create a health powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the heath powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is HEALTH_BOOST.

Test Case 9: createSpeedPowerupConfigTest

Objective: To verify the creation of a speed powerup config.

Steps:

  • Use PowerupConfig to create a speed powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the speed powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is SPEED_BOOST.

Test Case 10: createExtraLifePowerupConfigTest

Objective: To verify the creation of a health powerup config.

Steps:

  • Use PowerupConfig to create an extra life powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the extra life powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is EXTRA_LIFE.

Test Case 11: createDoubleCrossPowerupConfigTest

Objective: To verify the creation of the double cross powerup config.

Steps:

  • Use PowerupConfig to create a double cross powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the double cross powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is DOUBLE_CROSS.

Test Case 12: createDoubleDamagePowerupConfigTest

Objective: To verify the creation of a double damage powerup config.

Steps:

  • Use PowerupConfig to create a double damage powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the double damage powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is DOUBLE_DAMAGE.

Test Case 13: createSnapPowerupConfigTest

Objective: To verify the creation of a Snap powerup config.

Steps:

  • Use PowerupConfig to create a Snap powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the Snap powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is SNAP.

Test Case 14: createTempImmunityPowerupConfigTest

Objective: To verify the creation of an immunity powerup config.

Steps:

  • Use PowerupConfig to create an immunity powerup config.
  • Check that the created powerup config is not null.
  • Use PowerupFactory to create a powerup entity based on the immunity powerup config.
  • Extract the PowerupType from the created powerup entity.
  • Check that the created powerup entity is not null.
  • Validate that the powerup entity type is TEMP_IMMUNITY.

Assumptions:

  • The ServiceLocator class works correctly and has been previously tested.
  • The PowerupComponent class has methods and behaviour that are correctly implemented. External extensions such as MockitoExtension and GameExtension have the expected behaviour.

Dependencies:

The test class relies on external resources such as images (images/healthpowerup.png, images/speedpowerup.png and images/extralifepowerup.png).


Test Plan for PowerupComponent

Objective:

To validate the correct behaviour of various power-up effects in the PowerupComponent class, ensuring:

  • The health power-up effectively sets an entity's health to full.
  • The speed power-up properly sets an entity's speed.
  • The extra life power-up properly increases the player's lives by 1, unless the player has 4 lives.
  • The get and set operations for power-up type and duration are accurate.

Methodology:

Test Case 1: shouldApplyExtraLife

Objective: To validate the effect of an extra life power-up on an entity's player lives.

Steps:

  1. Mock necessary components and services.
  2. Create an extra life power-up component.
  3. Apply the extra life on a player entity, with 1 life, as defined in CombatStatsComponent.
  4. Ensure that the number of player's lives is 2.
  5. Apply the extra life on the player entity.
  6. Ensure that the number of player's lives is 3.

Test Case 2: testExtraLifeMaxReached

Objective: To validate the effect of an extra life power-up on an entity's player lives.

Steps:

  1. Mock necessary components and services.
  2. Create an extra life power-up component.
  3. Apply the extra life on a player entity, with 4 lives, as defined in CombatStatsComponent.
  4. Ensure that the number of players' lives is still 4 since the max number of player lives has been reached.

Test Case 3: shouldApplyHealthBoost

Objective: To validate the effect of a health power-up on an entity's combat stats.

Steps:

  1. Mock necessary components and services.
  2. Create a health power-up component.
  3. Apply the power-up effect on a mock player entity.
  4. Validate that the player's health is set to full (100).

Test Case 4: shouldApplySpeedBoost

Objective: To validate the effect of a speed power-up on an entity's player actions.

Steps:

  1. Mock necessary components and services.
  2. Create a speed power-up component.
  3. Apply the speed effect on a mock player entity.
  4. Ensure the player's speed is set to (5, 5).

Test Case 5: shouldApplyTempImmunity

Objective: To validate the effect of a temp immunity power-up on an entity's player actions.

Steps:

  1. Mock necessary components and services.
  2. Create a temp immunity power-up component.
  3. Apply the temp immunity effect on a mock player entity.
  4. Ensure the player and companion are immune.
  5. Ensure the player and companion are not immune after 7 seconds.

Test Case 6: shouldApplyDoubleDamage

Objective: To validate the effect of a double damage power-up on an entity's player actions.

Steps:

  1. Mock necessary components and services.
  2. Create a double damage power-up component.
  3. Apply the double damage effect on a mock player entity.
  4. Ensure the player has an attack multiplier of 2.
  5. Ensure the attack multiplier is reset.

Test Case 7: shouldApplySnap

Objective: To validate the effect of a snap power-up on an entity's player actions.

Steps:

  1. Mock necessary components and services.
  2. Mock two enemies.
  3. Create a snap power-up component.
  4. Apply the snap effect on a mock player entity.
  5. Ensure that the size of the enemies list is 1.

Test Case 8: testGetType

Objective: To validate the retrieval of the type of power-up component.

Steps:

  1. Create health and speed power-up components.
  2. Validate that the type retrieved from each component is accurate.

Test Case 9: testSetType

Objective: To validate the ability to change the type of a power-up component.

Steps:

  1. Initialize health and speed power-up components.
  2. Set a new type for each component.
  3. Validate that the newly set type is retrieved accurately.

Test Case 10: testSetDuration

Objective: To validate the ability to set the duration of the power-up effect.

Steps:

  1. Create a health power-up component.
  2. Set different durations for the power-up effect.
  3. Ensure that the set duration matches the retrieved value.

Test Case 11: testGetDuration

Objective: To validate the retrieval of the duration of the power-up effect.

Steps:

  1. Initialize a health power-up component and set a duration.
  2. Validate that the retrieved duration is accurate.

Dependencies:

  • The PowerupComponentTest class relies on external libraries like libGDX for game-related functionalities.
  • Mocking frameworks such as Mockito are essential for simulating real-world interactions.
Clone this wiki locally