Skip to content

Dialogue Box Service Testing

Min edited this page Sep 10, 2024 · 6 revisions

Both the Dialogue Box and Dialogue Box Service are tested in parallel. This makes sense as in the design process the Dialogue Box Service was made to be the only interface between some method / class and the Dialogue Box.

DialogueBoxServiceTest

This class contains unit tests for the DialogueBoxService class, which manages the display and functionality of dialogue boxes in the game. It ensures that various features of the DialogueBoxService are working as expected.

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.
Clone this wiki locally