1 package org
.codehaus
.groovy
.grails
.cli
3 class CreateUnitTestTests
extends AbstractCliTests
{
6 void testCreateUnitTest() {
7 appDir
= createTestApp()
10 tryUnitTest('org.example.Author')
11 tryUnitTest('project-item', 'ProjectItem')
14 void tryUnitTest(String className
) {
15 tryUnitTest(className
, className
)
18 void tryUnitTest(String scriptArg
, String className
) {
19 // Run the create unit test script with a single argument.
20 System
.setProperty("grails.cli.args", scriptArg
)
21 gantRun( ["-f", "scripts/CreateUnitTest.groovy"] as String
[])
23 // Extract any package from the class name.
25 def pos
= className
.lastIndexOf('.')
27 pkg
= className
[0..<pos
]
28 className
= className
[(pos
+ 1)..-1]
33 pkgPath
= pkg
.replace('.' as
char, '/' as
char) + '/'
36 // Check that the unit test has been created.
37 // Now check that the associated test has also been created.
38 def testFile
= new File("${appDir}/test/unit/${pkgPath}${className}Tests.groovy")
39 assert testFile
.exists()
40 assert testFile
.text
=~
"^${pkg ? 'package ' + pkg : ''}\\s*class ${className}Tests extends GroovyTestCase \\{"