开发者

call to .save() on domain class fails with no signature of method .save() in unit test

开发者 https://www.devze.com 2023-03-22 07:06 出处:网络
I\'m using Grails 1.3.2 in NetBeans. I have a very simple unit test that fails with this error: No signature of method: com.maxrecall.maxrequire.domain.Release.save()

I'm using Grails 1.3.2 in NetBeans. I have a very simple unit test that fails with this error:

No signature of method: com.maxrecall.maxrequire.domain.Release.save() 开发者_StackOverflow is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true]] Possible solutions: wait(), any(), wait(long), isCase(java.lang.Object), use([Ljava.lang.Object;), sleep(long)

The relevant code is:

Release rel = new Release()
...
rel.save(flush:true) 

The same code works in BootStrap.groovy. I have tried various variations on .save() (.Save with and without parameters.


It's a unit test, so there's no Spring, Hibernate, etc. You have to mock the behavior you want.

If you're testing persistence, you need to convert the test to an integration test, since testing persistence with unit tests just tests the mocking framework. An integration test uses at a minimum an in-memory database, although you can easily switch that for a test instance of MySQL/Oracle/etc.

If you're testing controllers or other users of your domain classes and just want them to work so you can focus on testing the current class, use mockDomain and the other mock methods available in the Grails unit test base classes.

This is all described in detail in the documentation - see http://grails.org/doc/latest/guide/9.%20Testing.html


There's no grails magic around in a unit test (it's there in an integration test). See "Understanding mockDomain()" here or read the Grails docs.

0

精彩评论

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