Skip to content

State Interaction Helper Classes Testing Plan

Henry Batt edited this page Aug 31, 2023 · 5 revisions

Introduction:

The State Interaction Helper Classes consisting of the GameStateObserver and GameStateInteraction are essential components due to being the point of interface with the game and the stored game state data. As a result, it is vital to ensure it behaves as expected.

Test Plan for GameStateInteraction:

Objective:

The objective is to validate the game state interaction to ensure it modifies the game state appropriately by ensuring:

  • When new data is added in a key-value pair, the game state reflects this change.
  • When accessing data by a key the most recently saved data is returned.
  • Custom updating methods behave as expected to modify data without overwriting it.

Methodology:

SetUp (BeforeEach):

  • A new GameState is created to store all the data and reflect changes.
  • A GameStateInteraction instance is generated to test.

Test Case 1: testPutData

Objective: To ensure that when data is added through the helper it gets stored correctly using two different value types (String and Int).

Steps:

  • Two key-value pairs are generated.
  • The data is added to through the game state interaction.
  • Using the given key, the data is retrieved directly from the GameState.
  • Validate that the retrieved data is identical to the added data.

Test Case 2: testGetData

Objective: To validate that when getting data it retrieves the correct and up to date version from the game state.

Steps:

  • Two sets of testing data were inserted into the GameState one with an int value and the other a String.
  • The data was then retrieved using the given key and interaction.
  • Validate that the retrieved data using the key is identical to what was set for the integer value.
  • Validate that the retrieved data for the String value key is identical to what was set.
  • Validate that if the key does not exist it returns null.

Test Case 3: testGetAllStateData

Objective: To validate that a copy of the entire game state data can be retrieved.

Steps:

  • Testing data is added into the GameState.
  • A copy of the game state is retrieved.
  • Validate that the retrieved copy data is identical to what is expected.

Test Case 4: testUpdateResource

Objective: To ensure that updating a resource amount in the game state works correctly.

Steps:

  • An initial amount of a resource is stored in the game state.
  • The resource amount is then updated by an amount.
  • The newly saved amount is then retrieved.
  • Validate that the amount is what is expected (Original amount + updated amount)

Dependencies:

  • The GameStateInteraction class is dependent on the GameState being implemented to store all the data

Test Plan for GameStateObserver:

Objective:

The primary objective is to verify the functionality and behaviour of the GameStateObserver.

Methodology:

SetUp (BeforeEach):

  • A GameStateInteraction object and a GameStateObserver object are created.
  • GameStateObserver object is set up with GameStateInteraction object.

Test Case 1: testAddListener

Objective: To ascertain whether listeners can be correctly added and triggered.

Steps:

  • Define an AtomicInteger variable and a Listener which captures and sets this Atomic Integer value on trigger.
  • Associate the listener with a key: "testListener1".
  • Trigger the listener using its key, and pass an integer value.
  • Validate that value captured by AtomicInteger is equal to the initially passed value.

Test Case 2: testTriggerCallback

Objective: To verify that the triggering of a callback updates the state as expected.

Steps:

  • Define a resource name and an amount.
  • Trigger the "resourceAdd" callback with the resource name and amount.
  • Validate that the state has been updated correctly, i.e., the value for the key "resource/'resource name'" should be equal to the amount.

Test Case 3: testGetStateData

Objective: To validate that getting data from the state is working correctly.

Steps:

  • Define and add two key-value pairs to the state.
  • Use the keys to get the values from state via GameStateObserver.
  • Validate that the retrieved values match the added values.
  • Test a key not present in GameState should return null when trying to retrieve it.

Dependencies:

  • The GameStateObserverTest class is dependent on the GameStateInteraction class.
  • The Listener functions associated with GameStateObserver need to be functioning correctly.
  • This class also relies on Junit 5 for @BeforeEach, @Test annotations and the assertEquals function for assertions.
Clone this wiki locally