Skip to content

PlayerActionsTest Class

24msingh24 edited this page Oct 5, 2023 · 2 revisions

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

  1. Prerequisites
  2. Test Description
  3. Test Setup
  4. Test Execution
  5. Expected Results
  6. Conclusion

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, and Body 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

Testing walk

The testWalk method tests the walk method of the PlayerActions class. It involves the following steps:

  1. Creating an instance of the PlayerActions class.
  2. Setting up the entity and associated dependencies.
  3. Defining a walk direction vector.
  4. Calling the walk method with the walk direction vector.
  5. Asserting that the walkDirection field of PlayerActions matches the expected walk direction.

Testing stopWalking

The testStopWalking method tests the stopWalking method of the PlayerActions class. It involves the following steps:

  1. Creating an instance of the PlayerActions class.
  2. Setting up the entity and associated dependencies.
  3. Defining a walk direction vector and calling the walk method.
  4. Verifying that the player is no longer moving by checking the isMoving method.

UML

Screenshot 2023-10-05 at 2 23 17 PM

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.

Clone this wiki locally