PlayerActionsTest Class - UQcsse3200/2023-studio-2 GitHub Wiki
PlayerActionsTest Class Documentation
Overview
The PlayerActionsTest
class is a JUnit test class designed to test the functionality of the PlayerActions
class in your game. The PlayerActions
class is responsible for controlling player actions such as walking and stopping. This test class verifies that the methods of the PlayerActions
class, such as walk
and stopWalking
, work correctly.
Table of Contents
Prerequisites
Before running the PlayerActionsTest
class, ensure that you have the following prerequisites in place:
- A working Java development environment.
- JUnit and relevant dependencies added to your project.
- The
PlayerActions
class that is being tested. - The
Entity
,PhysicsComponent
, andBody
classes used for testing.
Test Description
The primary objective of the PlayerActionsTest
class is to validate the behavior of the methods in the PlayerActions
class. These methods control player actions such as walking and stopping. This test class ensures that these actions are performed correctly.
Test Setup
Mocking Dependencies
In this test class, Mockito is used to mock the Entity
, PhysicsComponent
, and Body
classes, which are dependencies of the PlayerActions
class. The MockitoAnnotations.initMocks(this)
method is called in the setUp
method to initialize these mocks. Additionally, the behavior of the mocked objects is defined using when
statements.
Test Execution
walk
Testing The testWalk
method tests the walk
method of the PlayerActions
class. It involves the following steps:
- Creating an instance of the
PlayerActions
class. - Setting up the entity and associated dependencies.
- Defining a walk direction vector.
- Calling the
walk
method with the walk direction vector. - Asserting that the
walkDirection
field ofPlayerActions
matches the expected walk direction.
stopWalking
Testing The testStopWalking
method tests the stopWalking
method of the PlayerActions
class. It involves the following steps:
- Creating an instance of the
PlayerActions
class. - Setting up the entity and associated dependencies.
- Defining a walk direction vector and calling the
walk
method. - Verifying that the player is no longer moving by checking the
isMoving
method.
UML
Conclusion
The PlayerActionsTest
class is crucial for verifying the functionality of the PlayerActions
class, which controls player actions within the game. By conducting these tests, you can confirm that walking and stopping are working as expected, contributing to the overall reliability and functionality of the player control system.