Factored out some of the test code