Skip to content

DroidCombatTask Test Plan

Mohamad Dabboussi edited this page Sep 11, 2023 · 1 revision

Test Plan for DroidCombatTask Class

Introduction

The DroidCombatTask class is a crucial component in our game's architecture, responsible for determining the behavior and actions of the Droid Towers in the game environment. The class operates based on a Finite State Machine (FSM) and employs various states to guide the tower's actions. This document aims to outline a detailed test plan for this class, focusing primarily on the updateTowerState() method and its underlying functionalities.

Objective

The primary objectives of this test plan are:

  1. To verify correct state transitions within updateTowerState().
  2. To ensure the accurate triggering of events in accordance with each state.
  3. To test the effectiveness of utility methods like isTargetVisible() in the state transition logic.

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. Instantiate a DroidCombatTask object for testing.

Test Cases

Test Case 1: testStartTriggersWalkEvent

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

Steps:

  1. Create a mock Droid entity and a mock EventListener0 for the WALK event.
  2. Invoke start() method on the DroidCombatTask instance.
  3. Verify that the WALK event is triggered.

Test Case 2: testUpdateTowerStateWithTargetInRange

Objective: To confirm correct state transitions and event triggers when a target is within the defined range.

Steps:

  1. Create mock Droid and NPC entities and position them within the defined range.
  2. Attach mock EventListener0s for the ATTACK_UP, ATTACK_DOWN, SHOOT_UP, and SHOOT_DOWN events.
  3. Update the PhysicsService and the Droid entity.
  4. Assert that the Droid transitions through states as expected and that the appropriate events are triggered.

Test Case 3: testUpdateTowerStateWithTargetNotInRange

Objective: To verify that the Droid stays in the IDLE state when no target is in range.

Steps:

  1. Create mock Droid and NPC entities and position them out of range.
  2. Attach mock EventListener0 for the IDLE event.
  3. Update the PhysicsService and the Droid entity.
  4. Assert that the Droid remains in the IDLE state and no other events are triggered.

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