Move before test logic to test.sh