Skip to content

Instantly share code, notes, and snippets.

@krsmes
Created January 21, 2011 21:41
Show Gist options
  • Save krsmes/790480 to your computer and use it in GitHub Desktop.
Save krsmes/790480 to your computer and use it in GitHub Desktop.
shell script for running grails tests
#!/bin/sh
proj=""
port=8091
function testUnit {
echo "Starting $1 unit tests for $proj"
grails test-app -unit $1
return $?
}
function testIntegration {
echo "Starting $1 integration tests for $proj"
grails test-app -integration $1
return $?
}
function testUnitIntegration {
echo "Starting unit and integration tests for $proj"
grails test-app -clean -unit -integration -coverage
return $?
}
function testFunctional {
local url="http://localhost:$port/$proj"
echo "Starting $1 functional tests for $proj on port $port"
grails -Dgrails.env=hsqldbmem -Dserver.port=$port -Dselenium.url=$url test-app -functional $1
return $?
}
case $1 in
unit)
testUnit $2
exit $# ;;
integration)
testIntegration $2
exit $# ;;
functional)
testFunctional $2
exit $# ;;
jasmine)
testFunctional test.jasmine.RunJasmineTests
exit $# ;;
all)
testUnitIntegration
[[ $# -eq 0 ]] && testFunctional
exit $# ;;
precheckin)
allIsOk="no"
testUnitIntegration
if [ "$?" -eq "0" ]; then
# Save coverage report, which is about to get deleted by running Selenium tests
coberturaDir="target/test-reports/cobertura"
tmpDir="/tmp/cobertura.$proj.$$"
mv $coberturaDir $tmpDir
testFunctional
[[ "$#" -eq "0" ]] && allIsOk="yes"
# Restore saved coverage report
mv $tmpDir $coberturaDir
fi
echo ""
echo ""
if [ $allIsOk == "yes" ] ; then
echo "******************************************************************"
echo " GREEN GREEN GREEN GREEN GREEN ($proj)"
echo "******************************************************************"
exit 0
else
echo "****************************"
echo " RED RED RED ($proj)"
echo " no check-in for you "
echo "****************************"
exit 1
fi
;;
*)
testUnitIntegration
exit $# ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment