Move test persistence infrastructure into helpers

This is the third (and hopefully last, at least in this project) major part of the work that's been started in #633 and continued in #645 with smaller detours in #638, #641 and #642.