Skip to content

TNTTowerCombatTask Test Plan

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

Test Documentation for TNTTowerCombatTask Class

Introduction

Ensuring that our game operates reliably requires exhaustive testing of the components that comprise its entities. The TNTTowerCombatTask class, responsible for managing the behavior and actions of our TNT Towers, is no exception. This document outlines the test plan that focuses on validating its Finite State Machine (FSM) based architecture and behavior, primarily concentrating on the updateTowerState() method.

Objective

The aim of this test plan is to validate:

  1. The proper state transition within updateTowerState().
  2. The accurate triggering of events corresponding to each state.
  3. The effectiveness of methods such as isTargetVisible() in state transition.

Methodology

Setup (BeforeEach)

  • Mock the GameTime service and register it with ServiceLocator.
  • Register a new PhysicsService and EntityService with the ServiceLocator.
  • Initialize a TNTTowerCombatTask instance.

Test Cases:

Test Case 1: testStartTriggersDefaultEvent

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

Steps:

  • Create a mock TNT entity and a mock EventListener0 for the default event.
  • Start the TNTTowerCombatTask and verify that the default event gets triggered.

Test Case 2: testUpdateTowerStateWithTargetInRange

Objective: To confirm that state transitions and event triggers work as expected when a target is within range.

Steps:

  • Create mock TNT and NPC entities and position them within range.
  • Add mock EventListeners for dig, explode, and damage events.
  • Update the PhysicsService and entities.
  • Check if the TNT is in the correct state and the appropriate events are triggered.

Test Case 3: testStayAtIdleWhenNoTargetInRange

Objective: To validate that the tower stays in the IDLE state when no target is in range.

Steps:

  • Create mock TNT and NPC entities and position them out of range.
  • Update the PhysicsService and entities.
  • Confirm that the state remains at IDLE and no unnecessary interactions occur.

Assumptions

  • Classes such as ServiceLocator, CombatStatsComponent, PhysicsComponent, and HitboxComponent are properly implemented and previously tested.
  • External libraries like Mockito and JUnit function as expected.

Sample Test Code

The test code uses JUnit and Mockito for testing. It sets up the environment, mocks the necessary components, and verifies the expected behavior for each test case.

This test plan and accompanying test code provide a comprehensive methodology to validate that the TNTTowerCombatTask class and its updateTowerState() method function as expected.

Clone this wiki locally