refactor test, add common machinery