Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
223 lines (182 sloc) 9.89 KB
<project name="grails-functional-test" default="functional-test">
<property environment="env"/>
<property name="checkoutDir" location="apps"/>
<property name="newWebApp" value="myTestWebApp"/>
<property name="target" value="target"/>
<property name="default.port" value="8183"/>
<path id="classpath">
<fileset dir="lib" includes="*.jar"/>
</path>
<import file="./common/macros.xml" />
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="classpath"/>
<target name="init">
<groovy>
ant.property(name:"grails.home", location:"../grails")
</groovy>
<condition property="grailsCmd" value="grails.bat" else="grails">
<os family="windows"/>
</condition>
<property name="grailsCmd.absolute" location="${grails.home}/bin/${grailsCmd}"/>
</target>
<target name="-build-grails">
<echo>GRAILS_HOME=${grails.home}</echo>
<ant dir="${grails.home}" antfile="build.xml" target="jar">
<property name="skipTests" value="true"/>
<property name="skipExamples" value="true"/>
</ant>
</target>
<target name="functional-test"
description="Runs functional tests for one or more test applications from SVN"
depends="clean-reports,init,-build-grails,-testsWithNewApp">
<mkdir dir="reports" />
<antcall target="-functional-test-apps" />
<antcall target="-functional-test-scripts" />
</target>
<target name="run-test-scripts" depends="clean-reports,init">
<antcall target="-functional-test-scripts" />
</target>
<target name="-functional-test-scripts">
<delete dir="target/scripts" failonerror="false" />
<mkdir dir="target/scripts" />
<groovy>
String scriptName = ant.antProject.properties."test.script.name"
def scriptFiles = new File("scripts").listFiles().findAll { it.name.endsWith('.xml') }
if(scriptName) {
println "Running functional test script: $scriptName"
def file = scriptFiles.find{ it.name.startsWith(scriptName) }
if(file) {
ant.ant(antfile:file, inheritRefs:true)
}
else {
ant.fail("No test script found for name $scriptName")
}
}
else {
println "Running all functional test scripts!"
scriptFiles.each { file ->
ant.ant(antfile:file, inheritRefs:true)
}
}
</groovy>
</target>
<target name="-functional-test-apps">
<groovy><![CDATA[
try {
def outcomes = []
def failure = false
def grailsInvocationCounter = 0
new File('apps').eachDir { appDir ->
properties.projectName = appDir.name
// skip webtest based tests until plugin is fixed
if(properties.projectName == 'HelloWorld') return
// Clear any existing webtest and functional test plugins.
ant.echo message: "Delete existing webtest/functional test plugins"
ant.delete(includeemptydirs: true) {
fileset(dir: appDir.path, includes: "**/webtest-*/**/*")
fileset(dir: appDir.path, includes: "**/functional-test-*/**/*")
}
// First upgrade.
ant.grails(command:"upgrade -force", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't upgrade application ${properties.projectName}"
failure = true
}
// Install the appropriate testing plugin, run the tests, and check the reports..
if (new File(appDir, "test/functional").exists()) {
// Install the Functional Test plugin.
ant.grails(command:"install-plugin", args:"functional-test 1.2.2", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't install functional-test plugin into application ${properties.projectName}"
failure = true
}
// Run the tests.
ant.grails(command:"functional-tests", args: "--dev-mode", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}")
ant.copy(todir:"reports/${properties.projectName}") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/test/reports")
}
// Run the WAR tests.
ant.grails(command:"functional-tests", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}_war")
ant.copy(todir:"reports/${properties.projectName}_war") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/test/reports")
}
}
else {
// Install the WebTest plugin.
ant.grails(command:"install-plugin", args: "webtest", projectName:properties.projectName, resultID:grailsInvocationCounter++)
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
outcomes << "Couldn't install webtest plugin into application ${properties.projectName}"
failure = true
}
// Run the tests.
ant.grails(command:"run-webtest", environment:"dev", projectName:properties.projectName, resultID:grailsInvocationCounter++)
outcomes << "Functional tests in application ${properties.projectName}: " +
((properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) ? "Failed" : "OK")
if (properties["testResult_${grailsInvocationCounter-1}"].toInteger() != 0) {
failure = true
}
// Copy reports
ant.mkdir(dir:"reports/${properties.projectName}")
ant.copy(todir:"reports/${properties.projectName}") {
fileset(dir:"${properties.checkoutDir}/${properties.projectName}/webtest/reports")
}
}
}
println "Grails Functional Test Results"
println "======================================================"
outcomes.each() {
println it
}
if (failure) ant.fail(message:"At least one of the tests failed")
}
catch(Exception e) {
println e.message
e.printStackTrace()
ant.fail(message:"functional tests failed due to error")
}
]]>
</groovy>
</target>
<target name="-testsWithNewApp">
<echo>Creating new Grails app ${newWebApp} and running some tests on it</echo>
<property name="newWebApp.dir" value="${target}/${newWebApp}"/>
<delete dir="${newWebApp.dir}"/>
<mkdir dir="${target}"/>
<grails command="create-app ${newWebApp}" dir="${target}" failonerror="true"/>
<grails command="clean" dir="${newWebApp.dir}" failonerror="true"/>
<grails command="compile" dir="${newWebApp.dir}" failonerror="true"/>
<grails command="generate-all blog" dir="${newWebApp.dir}" failonerror="true"/>
<parallel>
<daemons>
<grails command="run-app" dir="${newWebApp.dir}" failonerror="true"/>
</daemons>
<sequential>
<waitfor maxwait="2" maxwaitunit="minute" checkevery="500">
<http url="http://localhost:${default.port}/${newWebApp}"/>
</waitfor>
<touch file="${newWebApp.dir}/.kill-run-app"/>
</sequential>
</parallel>
</target>
<target name="clean" depends="clean-reports">
<delete dir="reports" failonerror="false"/>
<delete dir="target" failonerror="false"/>
<delete dir="work-global" failonerror="false"/>
</target>
<target name="clean-reports">
<delete dir="reports" failonerror="false"/>
</target>
</project>
Jump to Line
Something went wrong with that request. Please try again.