EngineerCombatTask Test Plan - UQcsse3200/2023-studio-3 GitHub Wiki
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
- To verify that the state machine switches correctly through idle and firing states.
- To verify that the correct animation triggers are launched when switching states.
- To verify that the engineer is able to shoot projectiles towards enemy mobs.
Methodology
Setup (BeforeEach)
- Mock the
GameTimeservice and register it usingServiceLocator. - Initialize and register new instances of
PhysicsServiceandEntityServicewithServiceLocator. - Load sounds and animation images (Texture atlases) for the engineer entity.
- Create a new
EngineerCombatTaskand a mock engineer entity. - Add the
EngineerCombatTaskto the engineer'sAITaskComponentand set it as theTaskRunner.
Test Cases
Test Case 1: testIdleEvent
Objective: To confirm that invoking start() triggers the idleStart event.
Steps:
- Add a listener to the mock engineer for the
IdleStartevent. - Start the
EngineerCombatTask. - Update game physics.
- 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:
- Create a mock attacker entity with a
PhysicsLayerof 3. - Add a listener to the mock engineer for the
firingSingleStartevent. - Place the attacker beside the engineer and Start the
EngineerCombatTask. - Update game physics.
- 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:
- Create a mock attacker entity with a
PhysicsLayerof 3. - Place the attacker beside the engineer and Start the
EngineerCombatTask. - Update game physics so the Engineer detects the attacker and switches to firing state.
- Delete the attacker using
dispose()and add a listeneridleStartto engineer. - Update game physics so the engineer switches to the idle state.
- Ensure that the target is not visible, then verify that
idleStartwas triggered, otherwise fail.
Test Case 4: testProjectileFired
Objective: To verify that the Engineer spawns a projectile entity during the FIRING state.
Steps:
- Create a mock attacker entity with a
PhysicsLayerof 3. - Add a listener to the mock engineer for the
engineerProjectileFiredevent. - Place the attacker beside the engineer and Start the
EngineerCombatTask. - Update game physics.
- Verify the event call.
Assumptions
- Classes like
ServiceLocator,CombatStatsComponent,PhysicsComponent, andHitboxComponentare properly implemented and have been previously tested. - 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.