Skip to content

Map Test Plan

Anshuman0157 edited this page Oct 5, 2023 · 16 revisions

Spawning Custom Map Environment

The testing done to make sure that the custom tiled map appears on the screen was fairly simple as it was done by making sure that in the EarthGameArea, the spawnEnvironment() method made the map appear on the screen. We needed to test this as it was crucial in making sure that the custom map did indeed appear on the screen for the player, otherwise the entire experience could be ruined.

void spawnEnvironmentTest() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

    TerrainFactory terrainFactory = mock(TerrainFactory.class);
    TiledMapTileLayer tileLayer = mock(TiledMapTileLayer.class);
    TiledMap tiledMap = mock(TiledMap.class);
    GdxGame gdxGame = mock(GdxGame.class);
    MapLayers mapLayers = mock(MapLayers.class); // Mock MapLayers

    EarthGameArea earthGameArea = new EarthGameArea(terrainFactory, gdxGame);
    earthGameArea.terrain = mock(TerrainComponent.class);
    when(earthGameArea.terrain.getMap()).thenReturn(tiledMap);
    when(tiledMap.getLayers()).thenReturn(mapLayers); // Return the mock MapLayers
    when(mapLayers.get("Tree Base")).thenReturn(tileLayer); // Return the mock TileLayer

    EarthGameArea spyEarthGameArea = spy(earthGameArea);
    Method spawnEnvironmentMethod = EarthGameArea.class.getDeclaredMethod("spawnEnvironment");
    spawnEnvironmentMethod.setAccessible(true);
    spawnEnvironmentMethod.invoke(spyEarthGameArea);
}

Creating Custom Collisions

Testing the custom collision boxes was done by creating a custom collider and then verifying it was the same as a box of the same size. This ensures that the custom collision boxes are actually being created at the correct size and location, and if there is an error in this function, it would mean the player would have their movement hindered by a seemingly invisible wall.

void testSetCustomCollider(){

  ColliderComponent colliderComponentMock = mock(ColliderComponent.class);
  Entity entity = new Entity().addComponent(colliderComponentMock);

  PhysicsUtils.setCustomCollider(entity, 2.0f, 3.0f, 0.5f, 0.5f);
  verify(entity.getComponent(ColliderComponent.class)).setAsBox(
          new Vector2(2.0f, 3.0f), new Vector2(0.5f, 0.5f));

}

Testing environmental damage

Testing the functionalities of the EnvironmentStatsComponent class, which manages environmental effects in the game. In the damage() test case, a CombatStatsComponent object with 10 health points and a damage value of 1 is subjected to the damage() method of the EnvironmentStatsComponent. The test waits for 2 seconds and checks if the player's health decreases to 9, validating the proper functioning of the damage over time effect.

@Test
  void damage() throws InterruptedException {

    CombatStatsComponent player = new CombatStatsComponent(10, 10, 1, false);
    EnvironmentStatsComponent environmentStatsComponent = new EnvironmentStatsComponent();
    environmentStatsComponent.damage(player);

    // Wait for 2 seconds
    Thread.sleep(2000);
    assertEquals(9, player.getHealth(), "Health should be reduced after the timer delay");
  }

In the setImmunity() test case, a GameAreaConfig object representing the Earth map is created. The setImmunity() method of EnvironmentStatsComponent is invoked with this configuration. The test asserts that the player is not immune while on Earth, ensuring correct immunity behavior based on the game area.

void setImmunity() {

    GameAreaConfig earthMapConfig = new GameAreaConfig();
    earthMapConfig.mapName = "Earth";

    environmentStatsComponent.setImmunity(earthMapConfig);
    assertFalse(environmentStatsComponent.getImmunity(), "Entity should not be immune on Earth");
  }

Testing Custom Collision Box Location

The exact position of a collision box relative to the sprite location was tested manually. By enabling the debug mode in game, the outlines of all collision boxes are displayed on the screen. This was used to alter the locations of the collision boxes so they are properly centered around the sprite.

Clone this wiki locally