MapServiceTest - UQcsse3200/2023-studio-3 GitHub Wiki
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
MapServicecorrectly retrieves the associatedTerrainComponent. - To ensure that
MapServiceaccurately gets the height and width of the game map.
Methodology:
- Setup (BeforeEach):
- Mock the core components:
TerrainFactory,TerrainComponent, andEntity. - Set up the behavior for the mocked components using
when(). This includes linking theTerrainFactoryto create theTerrainComponentand theEntityto retrieve theTerrainComponent.
- Mock the core components:
Test Cases:
Test Case: testConstructor
Objective:
To ensure that the MapService correctly retrieves and stores the TerrainComponent associated with the given Entity.
Steps:
-
Service Initialization:
- Instantiate the
MapServicewith the mockedEntityandTerrainFactory.
- Instantiate the
-
Assertions:
- Confirm that the
TerrainComponentretrieved fromMapServicematches the mockedTerrainComponent.
- Confirm that the
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:
-
Mocking Map Bounds:
- Mock the behavior of the
TerrainComponentto return a specific height when queried for map bounds.
- Mock the behavior of the
-
Service Initialization and Method Invocation:
- Instantiate the
MapServiceand invoke itsgetHeight()method.
- Instantiate the
-
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:
-
Mocking Map Bounds:
- Mock the behavior of the
TerrainComponentto return a specific width when queried for map bounds.
- Mock the behavior of the
-
Service Initialization and Method Invocation:
- Instantiate the
MapServiceand invoke itsgetWidth()method.
- Instantiate the
-
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, andEntityfunction as expected during interaction withMapService. - The mocked behaviors defined in the setup are consistent across test cases.
Potential Challenges:
- Change in Terrain Configuration: If there are modifications to the terrain's design or structure, tests may need adjustments.
- Component Interactions: If the interaction method between
MapServiceand other components (likeEntityorTerrainComponent) changes, the tests will require updates.