开发者

Grails: Added methods during runtime available in tests?

I am trying to test a controller which, in particular, is using java.io.File and some of the methods/attributes injected by Grails during runtime, like:

empty fileI开发者_运维知识库tem transferTo()

I receive the following error:

No such property: empty for class: java.io.File

Some methods are easily implemented:

def testFile = new File('test/unit/resources/TestScript.groovy')
File.metaClass.getFileItem = { -> testFile }
File.metaClass.isEmpty = { -> false }

But others are not, so I wonder if there's a way to let Grails add them for me? My understanding was that this is done in integration tests but moving the test there gives me the same error.

Any help appreciated.

Thanks

Jonas


Does your test class inherit from GroovyTestCase or from ControllerUnitTestCase? For integration tests it should be GroovyTestCase.


True, I cannot find it in the javadocs either. Our action looks pretty much like the Listing 6 on the following site which is using it:

http://www.ibm.com/developerworks/java/library/j-grails06099/index.html

And interestingly enough I do not get the error with the following line:

File.metaClass.isEmpty = { -> false }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜