[#1117] Move some unit test code into helper functions