-
Notifications
You must be signed in to change notification settings - Fork 1
Dialogue Box Service Testing
To test various tasks of the Dialogue Box Service and Diaglogue Box, a mix of JUnit tests and in-game functionality tests were implemented. The tests ensure that dialogue interactions, entity highlighting, animations, and text updates work as expected. Below is a breakdown of the key testing areas and the corresponding tests. The tests can be found in the DialogueBoxServiceTest.java
and cover 66% of the lines in the Dialogue Box Class and covers 87% of the lines in Dialogue Box Service. Some of the lines of code were difficult to test using unit tests so see the bottom of the page for visual verification that resizing works.
Class-level Annotations:
-
@ExtendWith(GameExtension.class)
: Integrates with the game's extension to set up the necessary environment for testing.
Fields:
-
private DialogueBoxService entityChatService;
: Instance of theDialogueBoxService
to be tested. -
private static final Skin SKIN;
: Skin used for rendering UI elements. -
Stage stage;
: Mock stage used for rendering and UI interactions.
Setup:
-
@BeforeEach
: Initialises the necessary services and mocks before each test.
-
hideChatBox
: Verifies that hiding the dialogue box works as intended.-
Checks:
- The dialogue box is initially visible.
- The dialogue box becomes hidden when
hideCurrentOverlay()
is called.
-
Checks:
-
shouldCreateEntityChat
: Ensures that the dialogue box is created and updated correctly with the provided text.-
Checks:
- The dialogue box is created successfully.
- The hints array matches the input text.
-
Checks:
-
testButtonPresses
: Tests the functionality of the forward and backward buttons in the dialogue box.-
Checks:
- The forward button cycles through the hints in the correct order.
- The backward button cycles through the hints in reverse order.
-
Checks:
-
testOptionButtonPresses
: Tests the functionality of the option buttons in the dialogue box.-
Checks:
- Tests if the clicking on the options changes the dialogue box's text into the appropriate ones.
-
Checks:
-
shouldRemoveEntityChat
: Validates that the dialogue box can be properly disposed of.-
Checks:
- The dialogue box is removed when
disposeCurrentOverlay()
is called. - The
currentOverlay
becomesnull
.
- The dialogue box is removed when
-
Checks:
-
illegalDispose
: Tests the behavior of disposing the dialogue box when it has already been disposed.-
Checks:
- Ensures that calling
disposeCurrentOverlay()
on an already disposed dialogue box does not cause errors and results innull
currentOverlay
.
- Ensures that calling
-
Checks:
-
shouldUpdateEntityChat
: Confirms that updating the dialogue box with new text works correctly.-
Checks:
- The dialogue box displays the updated text.
- The hints array reflects the updated text correctly.
-
Checks:
-
buttonsExist
: Checks that the forward and backward buttons exist and are properly initialised.-
Checks:
- The forward and backward buttons are not
null
when the dialogue box is updated with new text.
- The forward and backward buttons are not
-
Checks:
Related to this there is the left and right arrow control of the dialogue box hints as well. These tests are included in this documentation as it relates specifically to the dialogue box testing. These have been tested in the KeyboardDialogueBoxInputComponentTest file. Specific testing for this includes:
-
testKeyDownRightArrow()
: Simulates pressing the RIGHT arrow key.
-
Checks:
- Calls
dialogueBoxService.getCurrentOverlay()
. - Triggers
dialogueBox.handleForwardButtonClick()
.
- Calls
-
testKeyDownLeftArrow()
: Simulates pressing the LEFT arrow key.
-
Checks:
- Calls
dialogueBoxService.getCurrentOverlay()
. - Triggers
dialogueBox.handleBackwardButtonClick()
.
- Calls
-
testKeyUp()
: Simulates releasing the RIGHT arrow key.
-
Checks:
- Returns
true
, indicating the key release was processed.
- Returns
-
testKeyDownWhenDisabled()
: Simulates pressing the RIGHT arrow key when the component is disabled.
-
Checks:
- Returns
false
, indicating input is ignored.
- Returns
Furthermore, entities that are interacting with the player will have an outline. The following tests check for the correct implementation and functionality.
-
shouldReturnCorrectVisibilityBoolean()
:
-
Checks:
- Returns false when overlay is not visible and true when it is.
-
shouldHighlightEntitySprite()
:
-
Checks:
- The current NPC has the correct animator "selected" which has the outline.
- The hints are updated correctly
-
shouldUnhighlightEntitySprite()
:
-
Checks:
- The current NPC has the correct animator "float" which does not have the outline as it is no longer interacting with the player.
-
shouldNotStartFloatAnimationIfNoPreviousEntity()
:
-
Checks:
- The current NPC remains selected and outlined as the text is updated.
-
shouldUnhighlightEntitySpriteAndHighlightNewEntity()
:
-
Checks:
- The interaction when a player stops interacting with one NPC and interacts with another.
- This ensures that the old NPC is unselected and the new NPC is selected.
-
shouldStartAnimationWhenAnimatorIsNotNull()
:
-
Checks:
- The NPC is highlighted when interacting with player.
Additionally, testing UI and resising of elements present a large challenge hence the resising methods inside the DialogueBoxService and DialogueBox were visually tested. Such methods include: DialogueBoxService::resiseElements and DialogueBox::resiseElements. To see this please see the video below: