Move part of testing code outside of the actual test to allow reusing it in other packages.