Item Pickup Testing - UQdeco2800/2021-ext-studio-2 GitHub Wiki

Plan

Test item picking up logic, i.e the logic that decides weather the player interacted with/picked up the first aid kit.

Testing Ecosystem

the GameExtension class makes it easy by mocking the ligdx and game-engine classes

@ExtendWith(GameExtension.class)
public class FirstAidComponentTest {

Java Lang Reflect: Used to access private methods and private fields of a class from the testing suite and make them accessible for testing purposes

JUnit: Used for assertions and class extendWith decorator plugins.

the logic of the item pick up system is to check that when the player interacts with the first aid kit and increase the health of the player when they do but not exceeding the maximum health of a 100.

creating the FirstAid Kit

the creating of this entity already has a function to check weather or not the first aid kit collides with the player layer

Entity createFirstAid(Entity target){
        Entity entity = new Entity()
                .addComponent(new PhysicsComponent())
                .addComponent(new ColliderComponent())
                .addComponent(new HitboxComponent())
                .addComponent(new FirstAidComponent(target));
        entity.create();
        return entity;

mimicking the player

mimicking the player identity

Entity createTarget() {
        Entity target =
                new Entity()
                        .addComponent(new CombatStatsComponent(100, 0))
                        .addComponent(new PhysicsComponent())
                        .addComponent(new HitboxComponent().setLayer(PhysicsLayer.PLAYER));
        target.create();
        return target;

sample test where health should be increased

@Test
    void shouldIncreaseHealth(){

        Entity target = createTarget();
        Entity entity = createFirstAid(target);
        Fixture entityFixture = entity.getComponent(HitboxComponent.class).getFixture();
        Fixture targetFixture = target.getComponent(HitboxComponent.class).getFixture();
        entity.getEvents().trigger("collisionStart", entityFixture, targetFixture);
        assertEquals(100, target.getComponent(CombatStatsComponent.class).getHealth());

    }

Future Plans

In the future add testing to check for the collision with the player and since more buffs will be added, add each buffs testing in association with the Item