Dialogue Box Service Testing - UQcsse3200/2024-studio-2 GitHub Wiki

DialogueBoxService 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 the DialogueBoxService 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.

Test Methods

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. shouldRemoveEntityChat: Validates that the dialogue box can be properly disposed of.

    • Checks:
      • The dialogue box is removed when disposeCurrentOverlay() is called.
      • The currentOverlay becomes null.
  6. 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 in null currentOverlay.
  7. 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.
  8. 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.

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:

  1. testKeyDownRightArrow(): Simulates pressing the RIGHT arrow key.
  • Checks:
    • Calls dialogueBoxService.getCurrentOverlay().
    • Triggers dialogueBox.handleForwardButtonClick().
  1. testKeyDownLeftArrow(): Simulates pressing the LEFT arrow key.
  • Checks:
    • Calls dialogueBoxService.getCurrentOverlay().
    • Triggers dialogueBox.handleBackwardButtonClick().
  1. testKeyUp(): Simulates releasing the RIGHT arrow key.
  • Checks:
    • Returns true, indicating the key release was processed.
  1. testKeyDownWhenDisabled(): Simulates pressing the RIGHT arrow key when the component is disabled.
  • Checks:
    • Returns false, indicating input is ignored.

Furthermore, entities that are interacting with the player will have an outline. The following tests check for the correct implementation and functionality.

  1. shouldReturnCorrectVisibilityBoolean():
  • Checks:
    • Returns false when overlay is not visible and true when it is.
  1. shouldHighlightEntitySprite():
  • Checks:
    • The current NPC has the correct animator "selected" which has the outline.
    • The hints are updated correctly
  1. 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.
  1. shouldNotStartFloatAnimationIfNoPreviousEntity():
  • Checks:
    • The current NPC remains selected and outlined as the text is updated.
  1. 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.
  1. 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:

CSSE3200 Screen Resising Visual Test