refactor test scripts to share code