Test Plan for KeyMapping - UQcsse3200/2024-studio-1 GitHub Wiki
Objective:
The goal is to verify that the KeyMapping
class is correctly handling default key bindings, allowing custom key bindings, and modifying the key map.
Test Cases:
1. Test Case: Verify Default Walk Key Mappings
- Description: Verify that the default key mappings for walking are set correctly when the class is initialized.
- Steps:
- Initialize the
KeyMapping
class. - Retrieve the default key map.
- Assert that the correct key bindings are set for walking (W, A, S, D).
- Initialize the
- Expected Result: The default key bindings should map W to
WALK_UP
, A toWALK_LEFT
, D toWALK_RIGHT
, and S toWALK_DOWN
.
2. Test Case: Verify Default Shoot Key Mappings
- Description: Verify that the default key mappings for shooting are set correctly.
- Steps:
- Initialize the
KeyMapping
class. - Retrieve the default key map.
- Assert that the correct key bindings are set for shooting (Arrow keys).
- Initialize the
- Expected Result: The default key bindings should map the arrow keys (LEFT, UP, RIGHT, DOWN) to shooting directions.
3. Test Case: Verify Default Item Key Mappings
- Description: Verify that the default key bindings for item usage are set correctly (e.g., Space for melee, numbers for item usage).
- Steps:
- Initialize the
KeyMapping
class. - Retrieve the default key map.
- Assert that the correct key bindings are set for items (Space for melee, numbers 1-3 for item usage).
- Initialize the
- Expected Result: Space should be mapped to
MELEE
, and numbers 1, 2, 3 should be mapped toUSE_1
,USE_2
, andUSE_3
.
4. Test Case: Set and Verify Custom Key Binding
- Description: Verify that a custom key binding can be set and is correctly reflected in the key map.
- Steps:
- Initialize the
KeyMapping
class. - Set a custom key binding for a new key (e.g., number 4).
- Retrieve the updated key map.
- Assert that the custom key binding has been set correctly.
- Initialize the
- Expected Result: Number 4 should be mapped to the new key binding (e.g.,
USE_4
).
5. Test Case: Verify Custom Key Mapping
- Description: Verify that a custom key mapping is returned correctly after setting it.
- Steps:
- Initialize the
KeyMapping
class. - Set a custom key binding for an unused key (e.g., F1).
- Retrieve the updated key map.
- Assert that the custom key binding is reflected in the key map.
- Initialize the
- Expected Result: F1 should be mapped to the new key binding (e.g.,
SHOOT_UP
).
6. Test Case: Modify Existing Key Binding
- Description: Verify that modifying an existing key binding updates the key map correctly.
- Steps:
- Initialize the
KeyMapping
class. - Set a key binding for a key (e.g., number 4).
- Modify the key binding for the same key.
- Retrieve the updated key map.
- Assert that the key binding has been updated, and the old binding no longer exists.
- Initialize the
- Expected Result: Number 4 should reflect the modified key binding (e.g., from
USE_4
toWALK_UP
), and the old binding should no longer be present.
Testing Environment:
- Unit Testing Framework: JUnit 5 (Jupiter)
- Extensions:
GameExtension
for LibGDX-related tests - Assertions: Use
assertEquals
andassertNotEquals
to verify correct key bindings.
Conclusion:
This test plan covers both the verification of default key bindings and the functionality of setting and modifying custom key mappings in the KeyMapping
class.