Testing Plan for Position Tracker - UQcsse3200/2024-studio-1 GitHub Wiki
PositionTracker
component
Test Plan for 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 likeRenderService
,EntityService
,PhysicsService
, andResourceService
. - Mocks are created for
WeaponFactory
andEntity
(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:
- Create a new
PositionTracker
. - Connect the mocked
player
entity to thePositionTracker
. - Disconnect the
player
from 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
PositionTracker
and a weaponEntity
that contains thePositionTracker
. - Set the initial position of the
player
to(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.