Extracted boilerplate code in tests into a common function.