Skip to content

EngineerCombatTask Test Plan

Praneet Dhoolia edited this page Sep 12, 2023 · 4 revisions

Test Plan for EngineerCombatTask

Introduction

The EngineerCombatTask class is a crucial component of the game mechanics, enabling engineers to shoot and detect enemy mobs. This class implements various states in the Engineer entity to help it perform a firing routine and switches through them based on enemy presence near the engineer.

Objective

  1. To verify that the state machine switches correctly through idle and firing states.
  2. To verify that the correct animation triggers are launched when switching states.
  3. To verify that the engineer is able to shoot projectiles towards enemy mobs.

Methodology

Setup (BeforeEach)

  1. Mock the GameTime service and register it using ServiceLocator.
  2. Initialize and register new instances of PhysicsService and EntityService with ServiceLocator.
  3. Load sounds and animation images (Texture atlases) for the engineer entity.
  4. Create a new EngineerCombatTask and a mock engineer entity.
  5. Add the EngineerCombatTask to the engineer's AITaskComponent and set it as the TaskRunner.

Test Cases

Test Case 1: testIdleEvent

Objective: To confirm that invoking start() triggers the idleStart event.

Steps:

  1. Add a listener to the mock engineer for the IdleStart event.
  2. Start the EngineerCombatTask.
  3. Update game physics.
  4. Verify the event call.

Test Case 2: testFiringEvent

Objective: To confirm that the Engineer enters the FIRING state when detecting one or more enemies.

Steps:

  1. Create a mock attacker entity with a PhysicsLayer of 3.
  2. Add a listener to the mock engineer for the firingSingleStart event.
  3. Place the attacker beside the engineer and Start the EngineerCombatTask.
  4. Update game physics.
  5. Verify the event call.

Test Case 3: testIdleAfterMobKilled

Objective: To verify that the Engineer switches back to the IDLE_RIGHT state after a mob isn't visible anymore.

Steps:

  1. Create a mock attacker entity with a PhysicsLayer of 3.
  2. Place the attacker beside the engineer and Start the EngineerCombatTask.
  3. Update game physics so the Engineer detects the attacker and switches to firing state.
  4. Delete the attacker using dispose() and add a listener idleStart to engineer.
  5. Update game physics so the engineer switches to the idle state.
  6. Ensure that the target is not visible, then verify that idleStart was triggered, otherwise fail.

Test Case 4: testProjectileFired

Objective: To verify that the Engineer spawns a projectile entity during the FIRING state.

Steps:

  1. Create a mock attacker entity with a PhysicsLayer of 3.
  2. Add a listener to the mock engineer for the engineerProjectileFired event.
  3. Place the attacker beside the engineer and Start the EngineerCombatTask.
  4. Update game physics.
  5. Verify the event call.

Assumptions

  1. Classes like ServiceLocator, CombatStatsComponent, PhysicsComponent, and HitboxComponent are properly implemented and have been previously tested.
  2. External libraries such as Mockito and JUnit are functioning as expected.

Sample Test Code

The test code leverages JUnit and Mockito frameworks to set up the testing environment, mock necessary components, and verify the expected behavior for each test case.

Clone this wiki locally