Refactor test files with contexts and change error messages in script files