A migration test that only asserts that the loader returned a document can go green while the player loses something. A renamed field can be absent, take its default value and still pass that assertion. The first useful change to the test is to give it a checkpoint with enough history that a wrong result is obvious.
Suppose your game saves the state of a pump room. An old build writes a checkpoint called pump-room-west, records that a valve is already open and deducts a fuse from the player’s inventory. The new build moves the checkpoint identifier to a field called respawn-point. This is a fictional example. You can run the same exercise with the equivalent data in your project and your current test harness.
The migration should preserve the checkpoint value and the spent fuse. It should leave unrelated records alone. If the checkpoint ID cannot be mapped, the rehearsal should fail in a way that identifies the offending value. These tests are small enough to put next to the migration code. The scene and storage checks that follow belong at a different layer.
1. Keep the fixture independent of the test
Use an old build to make one save with the valve open and one genuinely different save with it closed. Keep their original bytes outside the location the test runner can overwrite. Store a short description next to each file with the old build, schema, checkpoint and expected state. A fixture generated by the current serializer is useful when checking that serializer. It can’t expose a naming or format mismatch introduced by that same serializer.
Your test can copy the fixture into a disposable folder at setup. Avoid using the default slot your Editor opens during manual checks. Give each test its own writable copy so parallel tests and reruns don’t compete for the same file. Keep the setup path in the test report. When a failure only occurs on a player build, printed paths are often the difference between a useful defect and a report that says the file was missing.
If you can’t retain an old player save because it contains personal data or commercial assets, use a small fixture made in an old build with disposable data. Keep it representative. A progress field you expect to migrate should occur in the fixture, and it should have a value different from the new runtime default. That matters more than having a large save with hundreds of untouched records.
2. Assert exactly what changes
Exercise the migration on a copy or on an immutable in-memory document. Read the old field as the old schema read it. Apply the migration, then compare its output with an explicit list of expected changes. Assert that the replacement field is present with the resolved checkpoint. Assert that the superseded field is absent if the new contract removes it. Assert that the inventory record is unchanged.
Example assertions, independent of the save library
original.schema = 1
candidate.schema = 2
candidate.respawn-point = pump-room-west
candidate.valve-open = true
candidate.fuse-count = 0
original bytes unchanged
When the comparison reports a change you didn’t plan, decide whether it represents a new requirement or a bug. Don’t train the test to accept the entire output as a snapshot before resolving that question. A snapshot can preserve useful evidence, but an unexplained update to the expected output only makes the next failure harder to interpret. Start with assertions on the few values whose meaning is easy to explain to someone outside the migration code.
One useful negative case has both the old and new names in the same source document with different values. Decide which one the old build used and whether your new code can disambiguate them. If the history gives you no safe answer, refuse the migration and preserve the original. Silently preferring the new-looking field may produce a valid-looking checkpoint that the player never visited.
3. Distinguish invalid data from a stale source
An unknown checkpoint ID should fail during rehearsal. A source change while you are reviewing the candidate should fail during commit. These cases may both stop the release operation, but they point to different work. Fix the data or mapping for the first one. Reload and rehearse against the latest generation for the second.
You can test the stale-source behaviour without a race in the test runner. Read generation 3, prepare its candidate, then deliberately write an ordinary test save as generation 4. Try to commit the reviewed candidate with generation 3 as its expected source. The expected result is a refusal and a readable generation 4. Also verify that the candidate remains available for diagnosis if your application promises to retain it.
For multi-step schema changes, start one test from each version you still support. A schema 1 fixture might need to normalise an identifier before a schema 2 migration can move it to the new field. Test each step and the complete route. For a schema beyond the version you understand, make refusal a deliberate test. It’s much easier to diagnose a clear version mismatch than an accident in which an older build overwrites a save from a newer one.
Use separate assertions for a failed rehearsal and a source that changed after review.
4. Test what the loader hands to the game
Start a new session and load the migrated save through your actual game entry point. Check the first useful moment after loading. Can the player walk through the valve room? Are they standing on the right side of the door? Has the spent fuse stayed spent? A renderer or scene component can still disregard a value that the migration test returned correctly.
Make the test write a new checkpoint after loading and then restart the game again. This second load exercises the new write path. If your game has an autosave entry point that differs from a manual checkpoint, verify the one players will use after the update. Watch for an autosave that fires before the load has completed. It can overwrite the correct file with default scene state and make the defect appear to be a migration error.
Unity documents platform-specific locations for persistent data. Run the load test on the target player build and verify it is reading the fixture you intended. A test can otherwise “recover” from an empty Editor path by starting a new session that looks normal until you check the checkpoint and inventory.
5. Make the recovery assertion visible
Keep a disposable slot with at least two valid generations. Make the latest generation unreadable and record how you changed it. Ask the game to recover using its normal recovery route. Assert which older generation was selected. Then look for the actual older checkpoint in gameplay. If the recovered save is written as a new generation, check that its content matches the chosen older save and that the former generations remain where your retention policy says they should be.
Our recorded Windows Unity Editor fixture exercised a restore from generation 1 into a new generation 4. Before recovery the sample loaded level 4. In a fresh Play session after recovery it loaded level 2, and the earlier generations remained. Those level numbers are sample values. The check worth borrowing is that the game loaded the expected state in a new session, rather than relying on a successful restore dialog.
Run a final negative case with no valid generation left. Games differ in what recovery experience they can offer. The test should prove what yours promises, whether that’s guidance to contact support, a separate backup route, or a clearly labelled start-over choice. The application should preserve what you need to diagnose the failure instead of treating unreadable progress as a routine empty slot.
Leave the next developer a result they can reproduce
Record the fixture ID, source schema and generation, migration decision, target build and observed result. Include the expected checkpoint or another piece of state that is immediately visible. Note whether you tested a retry after a stale source and whether recovery was a real reload. This evidence can live in the release checklist so a teammate can verify the same behaviour even if the person who wrote the migration is unavailable.
Leave enough in the failure message to reproduce it
Suppose the second load starts in the right room but greys out a completed quest. A report that says “migration failed” sends the next developer looking for a parsing error. Give them the input build, fixture ID, test step and expected quest state. Include the observed state and whether it first appeared after the initial load or after a restart. Keep the fixture in the test store and refer to it by ID in the report. The person fixing the bug can then run the same check without asking a player for a copy of their save.
If you want an Editor view of the records alongside those checks, our Unity Editor tool for rehearsing save schema changes can inspect and compare supported records and restore retained generations. A suite like this is still the place to define what a correct migration means for your game.
Top comments (0)