Testing Plan for Position Tracker - UQcsse3200/2024-studio-1 GitHub Wiki

Test Plan for PositionTracker component

Objective

The purpose of this test plan is to validate the functionality of the PositionTracker class. This class is responsible for tracking the position of a player entity and updating the position of any connected weapon entity. The tests ensure that the PositionTracker correctly handles the creation of the tracker, connects and disconnects the player, and updates entity positions accordingly.

Test Environment

Framework: JUnit 5 with Mockito for mocking dependencies

Objects Used:

  • PositionTracker class for tracking player positions.
  • Entity class representing both the player and weapon entities.
  • WeaponFactory for creating weapon objects (mocked).
  • Vector2 for position management.

Setup:

  • The beforeEach() method registers necessary services like RenderService, EntityService, PhysicsService, and ResourceService.
  • Mocks are created for WeaponFactory and Entity (player entity).
  • Textures are loaded for projectiles to simulate game assets.

Test Cases

Test Case 1: Create PositionTracker

Objective: Validate the successful creation of the PositionTracker.

Setup: Instantiate a new PositionTracker.

Expected Outcome:

  • The PositionTracker instance is successfully created and is not null.

Test Case 2: Connect and Disconnect Player

Objective: Ensure the PositionTracker correctly connects and disconnects a player entity.

Setup:

  1. Create a new PositionTracker.
  2. Connect the mocked player entity to the PositionTracker.
  3. Disconnect the player from the PositionTracker.

Expected Outcome:

  • After connecting, the getPlayer() method should return the connected player.
  • After disconnecting, the getPlayer() method should return null.

Test Case 3: Update Position Tracking

Objective: Verify that the PositionTracker updates the position of the weapon entity to match the player's position.

Setup:

  1. Create a PositionTracker and a weapon Entity that contains the PositionTracker.
  2. Set the initial position of the player to (10, 10) and connect the player to the PositionTracker.
  3. Call update() and verify that the weapon entity's position matches the player's position.
  4. Change the player's position to (20, 20), call update() again, and verify that the weapon entity's position is updated correctly.

Expected Outcome:

  • After the first update, the weapon entity's position should match the player's initial position (10, 10).
  • After the second update, the weapon entity's position should update to (20, 20) to match the new player position.

Conclusion

This test plan ensures that the PositionTracker class behaves as expected when creating the tracker, connecting and disconnecting the player, and updating entity positions in response to changes in the player's position.