Skip to content

Commit 8ee121d

Browse files
author
graeme
committed
fix for GRAILS-1105
git-svn-id: https://svn.codehaus.org/grails/trunk@4143 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 16ae9c1 commit 8ee121d

File tree

4 files changed

+61
-34
lines changed

4 files changed

+61
-34
lines changed

lib/ant-junit.jar

70.7 KB
Binary file not shown.

lib/serializer.jar

184 KB
Binary file not shown.

lib/xalan.jar

2.94 MB
Binary file not shown.

scripts/TestApp.groovy

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,42 @@ import junit.framework.TestSuite;
3434
import junit.textui.TestRunner;
3535
import org.springframework.transaction.support.TransactionSynchronizationManager;
3636
import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator as GRC;
37+
import org.apache.tools.ant.taskdefs.optional.junit.*
3738

38-
Ant.property(environment:"env")
39-
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"
39+
Ant.property(environment:"env")
40+
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"
4041

4142
includeTargets << new File ( "${grailsHome}/scripts/Package.groovy" )
4243

43-
task ('default': "Run a Grails applications unit tests") {
44+
task ('default': "Run a Grails applications unit tests") {
4445
depends( classpath, checkVersion )
4546
grailsEnv = "test"
4647
packageApp()
4748
testApp()
48-
}
49+
}
50+
51+
testDir = "${basedir}/target/test-reports"
52+
53+
task(testApp:"The test app implementation task") {
54+
//runCompiledTests()
55+
Ant.mkdir(dir:testDir)
56+
Ant.mkdir(dir:"${testDir}/html")
57+
Ant.mkdir(dir:"${testDir}/plain")
4958

50-
task(testApp:"The test app implementation task") {
51-
//runCompiledTests()
5259
runGrailsTests()
53-
}
60+
}
5461

5562
task(runCompiledTests:"Runs the tests located under src/test which are compiled then executed") {
5663
compileTests()
57-
Ant.mkdir(dir:"${basedir}/target/test-reports")
58-
Ant.mkdir(dir:"${basedir}/target/test-reports/html")
5964
Ant.junit(fork:true, forkmode:"once") {
6065
jvmarg(value:"-Xmx256M")
6166

6267
formatter(type:"xml")
6368
batchtest(todir:"${basedir}/target/test-reports") {
6469
fileset(dir:"${basedir}/target/test-classes", includes:"**/*Tests.class")
6570
}
66-
}
67-
Ant.junitreport {
71+
}
72+
Ant.junitreport(tofile:"${testDir}/TEST-results.xml") {
6873
fileset(dir:"${basedir}/target/test-reports") {
6974
include(name:"TEST-*.xml")
7075
report(format:"frames", todir:"${basedir}/target/test-reports/html")
@@ -88,57 +93,79 @@ task(runGrailsTests:"Runs Grails' tests under the grails-test directory") {
8893
event("StatusFinal", [ "No tests found in grails-test to execute"])
8994
exit(0)
9095
}
91-
96+
9297
def ctx = GU.bootstrapGrailsFromClassPath()
93-
98+
9499
def app = ctx.getBean(GrailsApplication.APPLICATION_ID)
95100
def classLoader = app.classLoader
96101

97102
def resources = app.resourceLoader.resources as ArrayList
98103
testFiles.each() { resources << it }
99104
app.resourceLoader.resources = resources
100-
105+
101106
def suite = new TestSuite()
102-
107+
103108
GWU.bindMockWebRequest(ctx)
104-
109+
105110

106111
testFiles.each { r ->
107112
def c = classLoader.parseClass(r.file)
108113
if(TestCase.isAssignableFrom(c) && !Modifier.isAbstract(c.modifiers)) {
109114
suite.addTest(new GrailsTestSuite(ctx.beanFactory, c))
110-
}
115+
}
111116
}
112-
117+
113118
def beanNames = ctx.getBeanNamesForType(PersistenceContextInterceptor)
114119
def interceptor = null
115120
if(beanNames.size() > 0)interceptor = ctx.getBean(beanNames[0])
116-
121+
117122
result = new TestResult()
118123
try {
119-
interceptor?.init()
120-
124+
interceptor?.init()
125+
121126
suite.tests().each { test ->
122127
def thisTest = new TestResult()
123-
print "Running test ${test.name}..."
124-
suite.runTest(test, thisTest)
125-
if(thisTest.errorCount() > 0 || thisTest.failureCount() > 0) {
126-
println "FAILURE"
127-
thisTest.errors().each { result.addError(test, it.thrownException()); println it }
128-
thisTest.failures().each { result.addFailure(test, it.thrownException()); println it }
129-
}
130-
else { println "SUCCESS"}
131-
app.domainClasses.each { dc ->
132-
dc.clazz.executeUpdate("delete from ${dc.clazz.name}")
128+
new File("${testDir}/TEST-${test.name}.xml").withOutputStream { xmlOut ->
129+
new File("${testDir}/plain/TEST-${test.name}.txt").withOutputStream { plainOut ->
130+
def xmlOutput = new XMLJUnitResultFormatter(output:xmlOut)
131+
def plainOutput = new PlainJUnitResultFormatter(output:plainOut)
132+
def junitTest = new JUnitTest(test.name)
133+
thisTest.addListener(xmlOutput)
134+
thisTest.addListener(plainOutput)
135+
136+
plainOutput.startTestSuite(junitTest)
137+
xmlOutput.startTestSuite(junitTest)
138+
print "Running test ${test.name}..."
139+
suite.runTest(test, thisTest)
140+
plainOutput.endTestSuite(junitTest)
141+
xmlOutput.endTestSuite(junitTest)
142+
if(thisTest.errorCount() > 0 || thisTest.failureCount() > 0) {
143+
println "FAILURE"
144+
thisTest.errors().each { result.addError(test, it.thrownException()) }
145+
thisTest.failures().each { result.addFailure(test, it.thrownException()) }
146+
}
147+
else { println "SUCCESS"}
148+
app.domainClasses.each { dc ->
149+
dc.clazz.executeUpdate("delete from ${dc.clazz.name}")
150+
}
151+
}
133152
}
134153
interceptor?.flush()
135154
}
136-
}
155+
}
137156
finally {
138157
interceptor?.destroy()
139-
}
158+
}
140159

141-
}
160+
Ant.junitreport {
161+
fileset(dir:testDir) {
162+
include(name:"TEST-*.xml")
163+
}
164+
report(format:"frames", todir:"${basedir}/target/test-reports/html")
165+
}
166+
167+
168+
}
142169
catch(Throwable e) {
143170
event("StatusUpdate", [ "Error executing tests ${e.message}"])
144171
e.printStackTrace(System.out)

0 commit comments

Comments
 (0)