Skip to content

MapServiceTest

Mohamad Dabboussi edited this page Oct 2, 2023 · 1 revision

Test Plan for MapServiceTest Class


Introduction: The MapServiceTest class is devised to validate the functionality of the MapService class. This service is primarily designed for interaction with and management of the game map. The testing procedure aims to ensure that MapService accurately retrieves and manages data associated with the terrain, height, and width of the game map.


Objective: The primary objectives of this test plan are:

  • To verify that the MapService correctly retrieves the associated TerrainComponent.
  • To ensure that MapService accurately gets the height and width of the game map.

Methodology:

  • Setup (BeforeEach):
    1. Mock the core components: TerrainFactory, TerrainComponent, and Entity.
    2. Set up the behavior for the mocked components using when(). This includes linking the TerrainFactory to create the TerrainComponent and the Entity to retrieve the TerrainComponent.

Test Cases:

Test Case: testConstructor

Objective: To ensure that the MapService correctly retrieves and stores the TerrainComponent associated with the given Entity.

Steps:

  1. Service Initialization:

    • Instantiate the MapService with the mocked Entity and TerrainFactory.
  2. Assertions:

    • Confirm that the TerrainComponent retrieved from MapService matches the mocked TerrainComponent.

Expected Outcome: The TerrainComponent stored in MapService should match the mocked TerrainComponent.


Test Case: testGetHeight

Objective: To validate that the MapService correctly retrieves the height of the game map.

Steps:

  1. Mocking Map Bounds:

    • Mock the behavior of the TerrainComponent to return a specific height when queried for map bounds.
  2. Service Initialization and Method Invocation:

    • Instantiate the MapService and invoke its getHeight() method.
  3. Assertions:

    • Verify that the height retrieved matches the height defined in the mocked map bounds.

Expected Outcome: The height retrieved from MapService should be 2.


Test Case: testGetWidth

Objective: To validate that the MapService correctly retrieves the width of the game map.

Steps:

  1. Mocking Map Bounds:

    • Mock the behavior of the TerrainComponent to return a specific width when queried for map bounds.
  2. Service Initialization and Method Invocation:

    • Instantiate the MapService and invoke its getWidth() method.
  3. Assertions:

    • Verify that the width retrieved matches the width defined in the mocked map bounds.

Expected Outcome: The width retrieved from MapService should be 5.


Assumptions:

  • The core components such as TerrainFactory, TerrainComponent, and Entity function as expected during interaction with MapService.
  • The mocked behaviors defined in the setup are consistent across test cases.

Potential Challenges:

  1. Change in Terrain Configuration: If there are modifications to the terrain's design or structure, tests may need adjustments.
  2. Component Interactions: If the interaction method between MapService and other components (like Entity or TerrainComponent) changes, the tests will require updates.
Clone this wiki locally