Skip to content

Tile Highlighting Test

Mohamad Dabboussi edited this page Oct 15, 2023 · 2 revisions

Test Case: testTileHighlightOnHover in TerrainComponentTest

Objective: Confirm that hovering over a tile changes its texture based on the game's conditions, such as the player's currency or existing entities in the tile.


Overview:

The TerrainComponent class provides functionality to highlight tiles when they are hovered over by the cursor. Depending on the game's state, such as available currency or if a tower is placed, the tile might be highlighted in different colors. This test aims to confirm that these conditions correctly influence the tile's highlighting.


Steps:

  1. Initialize TerrainComponent:

    • Set up a mock TerrainComponent with a specified orientation, say TerrainOrientation.ORTHOGONAL for this test.
  2. Mock Gdx Input:

    • Use Mockito to mock the Gdx.input object.
    • Simulate a mouse position by setting values for getX() and getY() methods.
  3. Mock Map Components:

    • Create mock objects for the map layers, cells, and tiles to emulate a real map environment.
  4. Simulate Mouse Hover:

    • Call the hoverHighlight() method of TerrainComponent.
  5. Validation:

    • Depending on the test scenario (e.g., having enough currency to buy a tower or not), verify that the setTextureRegion method of the mock tile is called with the expected texture (e.g., green or red).

Expected Outcome:

When the mouse hovers over a tile, the tile's texture should be updated to represent the game's current state (e.g., whether the player can afford a tower or not).


Potential Challenges:

  1. Multiple Hover Regions: If the game design includes multiple hover states based on several conditions, this test might need to be adapted or expanded to cover those scenarios.

  2. Interactions with Other Systems: Ensure that the highlighting mechanism's interactions with other game systems are isolated so they don't interfere with the basic functionality of tile highlighting on hover.

  3. Tile Boundaries: It's essential to ensure that the highlighted region is constrained to the boundaries of the tile and does not overflow.


Detailed Test Scenarios:

  1. Green Highlight on Hover with Affordability:

    Objective: Ensure that the tile turns green when the player has enough currency to buy a specific tower type.

    Steps:

    • Use the setUp() method to initialize the required mocks.
    • Mock the tower type to be TowerType.WEAPON.
    • Ensure that the entity does not exist on the tile and that the player can afford the tower.
    • Simulate the hover action and verify that the tile's texture region changes to green.
  2. Red Highlight on Hover without Affordability:

    Objective: Ensure that the tile turns red when the player does not have enough currency to buy a specific tower type.

    Steps:

    • Use the setUp() method to initialize the required mocks.
    • Mock the tower type to be TowerType.TNT.
    • Ensure that the entity does not exist on the tile and that the player cannot afford the tower.
    • Simulate the hover action and verify that the tile's texture region changes to red.
Clone this wiki locally