Skip to content

Spawner Test Plan

Manvi Narang edited this page Oct 4, 2023 · 4 revisions

Introduction:

The SpawnerComponent class manages the spawning of enemy waves in a game. It tracks the timing and configuration of waves, handles the spawning of various enemy types based on the configuration, and updates the spawning state over time. It extends a generic game component (Component) and utilizes a GameTime service for time tracking. The class features methods like update, shouldSpawnNewWave, shouldSpawnEnemy, and handleEnemySpawn to control the spawning logic, and it allows for the configuration of different wave compositions through the SpawnerConfig parameter. The SpawnerComponent was tested in accordance with the following testing plan:

Test Plan for SpawnerComponent

Objective:

To validate that the Spawner is spawning in enemies

Methodology:

Test Case 1: testShouldSpawnNewWave_NotSpawningAndEnoughTimePassed

Objective: Ensure that the shouldSpawnNewWave method correctly determines whether a new wave should be spawned when the spawner is not currently spawning, and enough time has passed.

Steps:

  1. Initialize the spawner's state by indicating that it is not currently in the process of spawning a new wave.
  2. Determine the time when the last wave was spawned by subtracting the specified delay (WAVE_DELAY) from the current time.
  3. Invoke the method responsible for deciding whether a new wave should be spawned, passing in the current time.
  4. Check the output of the method to ensure that it returns 'true'.

Expected Outcome: The anticipated result is that the method returns true when the spawner is not presently engaged in spawning a wave, and a sufficient amount of time has elapsed since the last wave was spawned. This verifies that the spawner is ready to initiate a new wave under these conditions.

Test Case 2: testShouldSpawnNewWave_NotEnoughTimePassed

Objective: Ensure that the shouldSpawnNewWave method correctly determines that a new wave should not be spawned when not enough time has passed.

Steps:

  1. Initialize the spawner in a way such that it is currently not in the process of spawning a new wave.
  2. Invoke the method, passing the current time as an argument, indicating the time of the check.
  3. Check the output of the method to ensure it returns 'false'.

Expected Outcome: The expected outcome is that the method returns false. This signifies that, despite the spawner not being in the spawning state, the method correctly determines that not enough time has passed since the last wave, aligning with the objective of the test.

*Test Case 3: testShouldSpawnEnemy_IsSpawningAndEnoughTimePassed

Objective: Validate that the shouldSpawnEnemy method correctly determines whether an enemy should be spawned when the spawner is currently spawning, and enough time has passed.

Steps:

  1. Enable the spawning state of the spawner, indicating that it is actively generating enemies.
  2. Initialize the count of enemies already spawned to zero.
  3. Set the total number of enemies to spawn to one.
  4. Determine the time when the last enemy was spawned by subtracting the predefined delay for spawning (SPAWN_DELAY) from the current time.
  5. Execute the method responsible for deciding whether a new enemy should be spawned, providing the current time as an input parameter.
  6. Check if the method returns a true value, indicating that the conditions for spawning a new enemy are met.

Expected Outcome: The process aims to determine if the spawner should spawn a new enemy, returning true if the spawner is active (isSpawning is true), the spawned enemies are fewer than the total (enemiesSpawned < enemiesToSpawn), and sufficient time has passed (determined by SPAWN_DELAY).

*Test Case 4: testHandleNewWave_FirstWave

Objective: Validate that the handleNewWave method correctly initializes the spawner for the first wave based on the provided configuration.

Steps:

  1. Prepare a set of specific values representing the configuration for the first wave. These values may include the number of melee enemies (meleeEnemiesToSpawn), ranged enemies (rangedEnemiesToSpawn), and boss enemies (bossEnemiesToSpawn).
  2. Invoke the handleNewWave method, passing the current time as a parameter. This simulates the initiation of a new wave.
  3. Verify that internal variables (meleeEnemiesToSpawn, rangedEnemiesToSpawn, bossEnemiesToSpawn, currentWave, isSpawning) in the SpawnerComponent class accurately mirror the wave configuration, ensuring alignment with specified enemy counts for each type as per the provided configuration.

Expected Outcome: The expected outcome is that after calling handleNewWave with the current time, the SpawnerComponent instance should be properly configured for the first wave. The internal variables should be set in accordance with the specific values provided in the wave configuration. This includes the number of enemies to spawn, the current wave count, and the spawning state.

Clone this wiki locally