-
Notifications
You must be signed in to change notification settings - Fork 9
PlayerActionsTest Class
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.
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.
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.
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.
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.
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.
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.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files