Factorize code in tests some more