BackstoryCutscene Test Plan - UQcsse3200/2024-studio-3 GitHub Wiki

Test Environment

  • Framework: JUnit 4
  • Dependencies:
    • BackstoryCutscene: The main class under test.
    • ServiceLocator: Manages the services used in the game.
    • ResourceService, GameTime, EntityService: Registered services to support cutscene functionality.
    • Entity: A game entity to which BackstoryCutscene is attached.
    • EventHandler: Mocked event handlers for verifying event triggers.
    • Texture: Mocked texture objects for verifying resource loading.

Test Cases

1. Initialisation Test

  • Purpose: Verify that BackstoryCutscene is properly initialised with the necessary services and entity setup.
  • Setup:
    • Mock ResourceService, GameTime, Entity, and other dependencies.
    • Register necessary services in the ServiceLocator.
    • Initialise BackstoryCutscene and set the mock entity.
  • Expected Outcome:
    • BackstoryCutscene is initialised without errors.
    • The mock services are correctly set up in the ServiceLocator.
    • The Entity is correctly attached to the cutscene.

2. Load Assets Test

  • Purpose: Test that the correct textures are loaded during the cutscene's asset loading phase.
  • Setup:
    • Call backstoryCutscene.loadAssets().
  • Expected Outcome:
    • The ResourceService.loadTextures() method is called with the correct texture paths.
    • The ResourceService.loadAll() method is invoked exactly once.

3. Scene Setup Test

  • Purpose: Verify that the BackstoryCutscene properly sets up the scenes with the correct number of scenes, background images, and text content.
  • Setup:
    • Call backstoryCutscene.setupScenes().
  • Expected Outcome:
    • The number of scenes in the BackstoryCutscene matches the expected number (12 scenes).
    • The first scene has the correct background image path and scene text.
    • The background image path and text content are verified for accuracy.

4. Entity Creation Test

  • Purpose: Test that the cutscene creates and registers entities correctly when a scene is loaded.
  • Setup:
    • Call backstoryCutscene.setupScenes() and load the first scene with backstoryCutscene.loadScene(0).
  • Expected Outcome:
    • The EntityService.register() method is called once to register the background entity for the scene.

5. Cutscene Update Test

  • Purpose: Ensure that the cutscene completes after the set duration and triggers the correct events.
  • Setup:
    • Mock GameTime to simulate time passing (e.g., 0L and 5000L).
    • Call backstoryCutscene.update() before and after the simulated time has passed.
  • Expected Outcome:
    • Before the cutscene duration is up, no events are triggered.
    • After the cutscene duration, the "cutsceneEnded" event is triggered exactly once.

6. Asset Unload Test

  • Purpose: Verify that assets are properly unloaded when BackstoryCutscene is disposed of.
  • Setup:
    • Call backstoryCutscene.dispose().
  • Expected Outcome:
    • The ResourceService.unloadAssets() method is called with the correct texture paths, ensuring the assets are unloaded correctly.

7. Scene Transition Test

  • Purpose: Verify that the cutscene transitions correctly between scenes when nextCutscene() is called.
  • Setup:
    • Call backstoryCutscene.nextCutscene() after setting up the scenes.
  • Expected Outcome:
    • The currentSceneIndex is incremented and the next scene is loaded.
    • When the final scene is reached, the "cutsceneEnded" event is triggered.

8. Dispose Entities Test

  • Purpose: Ensure that entities are properly disposed of when transitioning between scenes or ending the cutscene.
  • Setup:
    • Mock the disposeEntities() method and trigger scene transitions.
  • Expected Outcome:
    • Entities from the previous scene are disposed of correctly, preventing memory leaks or reuse in the next scene.

Error Handling:

  • Purpose: Verify that BackstoryCutscene handles error scenarios such as missing scenes or assets.
  • Setup:
    • Simulate a scenario where scenes or assets are not loaded.
  • Expected Outcome:
    • The cutscene should not throw exceptions when assets are missing, and appropriate warnings should be logged.
    • The cutscene should gracefully handle the absence of scenes by ending the cutscene early or skipping missing scenes.

Logging Verification:

  • Ensure that all major actions (loading/unloading assets, transitioning scenes, disposing entities) are logged appropriately.
  • Log messages should be verified using mock loggers where applicable, ensuring that event-based logging provides sufficient information for debugging and testing purposes.