Skip to content

TowerFactory Test Plan

Shivam edited this page Sep 11, 2023 · 1 revision

Introduction

The TowerFactory is the main hub of towers that creates all the defensive towers in the game. All different tower Entities produced by TowerFactory are made using respective methods that use the base Entity created by createBaseTower method. Once the base entity is created, all the different components are added which provide towers with character and necessary properties. This documentation aims to outline a detailed test plan for this class, mainly testing for the added components to the created Entities.

Objective

The primary objectives of this test plan are:

  1. To verify if the components are added successfully to the Entities.
  2. To check component values for the added components.

Methodology

Setup (BeforeEach)

All the relevant files are loaded in a dictionary which is further loaded by the relevant components.

  1. Mock the GameTime and register is using the ServiceLocator.
  2. Initialise and register new instances of PhysicsService, RenderService and ResourceService using ServiceLocator.
  3. Load the relevant sound, texture and atlas files using the ResourceService loaded earlier
  4. Create new instances of all the towers that will be created using this TowerFactory.

Test Cases

Test case 1: testCreateBaseTowerNotNull

Objective: To confirm that the towers created using createBaseTower are actually entities and are not NULL

Steps:

  1. Check if the instances created in the setup are not equal to NULL using asserNotNull()

Test Case 2: testCreateBaseTowerHasColliderComponent

Objective: To check if the created base Entity has the ColliderComponent

Steps:

  1. Access the ColiderComponent of each tower using getComponent() method for entities and check if they are not equal to NULL

Test Case 3: testCreateBaseTowerHasHitboxComponent

Objective: To check if the created base Entity has the HitBoxComponent

Steps:

  1. Access the HitBoxComponent of each tower using getComponent() method for entities and check if they are not equal to NULL

Test Case 4: testCreateBaseTowerHasPhysicsComponent

Objective: To check if the created base Entity has the PhysicsComponent

Steps:

  1. Access the PhysicsComponent of each tower using getComponent() method for entities and check if they are not equal to NULL

Test Case 5: testWeaponTowerCombatStatsComponentAndCostComponent

Objective: To check if the created Entity contains the correct values for health, attack and cost of the tower.

Steps:

  1. Access the health of the tower using getComponent() for CombatStatsComponent and then access the attribute health. Further check if the output value matches the expected value.
  2. In order to check for the attack attribute follow step 1 of this test and replace the attribute name with attack and check if the output values matches the expected value.
  3. To check the cost of the tower, use the getComponents() method to access the CostComponent and check with the desired value.
  4. Repeat the above 3 steps for all the tower instances.

Test Case 6: weaponTowerHasAnimationComponent

Objective: To check if the created base Entity has the AnimationComponent

Steps:

  1. Access the AnimationComponent of each tower using getComponent() method for entities and check if it is not equal to NULL.
  2. Repeat the above step for all the instantiated towers.

Assumptions

  1. Methods like getComponent() function properly and are already tested before.
  2. All the externally added libraries (eg mockito) 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