Small refactor of test helpers

Also neater sort test