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:
PositionTrackerclass for tracking player positions.Entityclass representing both the player and weapon entities.WeaponFactoryfor creating weapon objects (mocked).Vector2for position management.
Setup:
- The
beforeEach()method registers necessary services likeRenderService,EntityService,PhysicsService, andResourceService. - Mocks are created for
WeaponFactoryandEntity(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
PositionTrackerinstance 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:
- Create a new
PositionTracker. - Connect the mocked
playerentity to thePositionTracker. - Disconnect the
playerfrom thePositionTracker.
Expected Outcome:
- After connecting, the
getPlayer()method should return the connectedplayer. - After disconnecting, the
getPlayer()method should returnnull.
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:
- Create a
PositionTrackerand a weaponEntitythat contains thePositionTracker. - Set the initial position of the
playerto(10, 10)and connect the player to thePositionTracker. - Call
update()and verify that the weapon entity's position matches the player's position. - Change the
player's position to(20, 20), callupdate()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.