# Make persistence behavior intentional and testable

> Verify what a browser game saves, what resets, and how it behaves when stored data is missing, stale or changed between sessions.

- URL: https://oneshotgems.ai/topics/testing-game-save-state
- Category: For game developers
- Type: Guide
- Updated: October 5, 2026

A save-state test starts with a product decision: which values should survive a reload, and which should reset for a fresh run? A best score may persist while a temporary power-up should not. Without an explicit rule, a tester cannot tell whether a remembered value is a feature or stale data. Make a short save contract first, then test persistence, reset, and recovery under conditions that resemble actual player use.

## Write down what survives each boundary

Create a small table for run restart, page reload, and a new browser session. Example: current score resets on restart; personal best survives reload; active level returns to level one after a new session. Name each value and the boundary it crosses. This makes it possible to spot accidental persistence, such as a previous run’s timer remaining visible after Restart, or accidental loss, such as a best score disappearing on reload.

## Probe missing, malformed and old values

Try a first visit with no saved key, then a valid saved score, then an empty or malformed value if you can control the test environment. A robust game should choose a defined fallback rather than display NaN, lock the menu, or crash before play. If a score has a maximum or must be a number, test negative, unexpectedly large, and nonnumeric inputs at the data boundary. These are resilience checks, not assumptions that players can edit storage through the product.

## Questions

**What should a game save between sessions?** That depends on the intended experience. State explicitly whether settings, best scores, progress, and in-progress runs persist, then test each at reload and new-session boundaries.

**Is localStorage guaranteed to be available?** No storage choice should be treated as an unconditional guarantee. Handle missing or unusable data gracefully and verify the game's fallback behavior in your supported environments.

## Follow your curiosity

- [Test Game State Transitions](https://oneshotgems.ai/topics/testing-game-state-transitions): Map a browser game's start, play, pause, win and loss states, then test every transition and the inputs that should be ignored.
- [A Regression Test Loop for Small Games](https://oneshotgems.ai/topics/game-regression-testing): Protect a working game loop after revisions with a short regression checklist focused on mechanics, scoring, restart and nearby edge cases.
- [Version Browser Game Data in Local Storage](https://oneshotgems.ai/topics/local-storage-game-versioning): Add a versioned save envelope and explicit migrations so browser games can handle older local data after their save shape changes.

## Further reading

- [MDN localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)

---
Canonical page: https://oneshotgems.ai/topics/testing-game-save-state
