Can Service Unit Test access Domain helper methods?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can Service Unit Test access Domain helper methods?

strayph
I have a problem where I am unit testing a service, but keep getting an error when trying to save (with flush) a created domain model:
groovy.lang.MissingMethodException: No signature of method: com.test.MyClass.save() is applicable for argument types: (java.util.LinkedHashMap) values: [[flush:true]]

I found an article from 2009 suggesting moving the Service Unit Test to a Service Integration Test:
http://tech.favoritemedium.com/2009/01/testing-grails-service-class.html

Is this still a valid concern?

My service does use multiple domain classes, and I am wondering about the "right" way to unit test the service.

Thanks,

Strayph
Reply | Threaded
Open this post in threaded view
|

Re: Can Service Unit Test access Domain helper methods?

Vivek Krishna-2
HI,

Inorder for domain class helper methods to be available in unit tests, you need to mock the domain class.

This can be done with
  mockDomain(com.test.MyDomainClass, myDomainClassList) // myDomainClassList is an optional list argument which can act as a replacement for the table in DB while unit testing. 

This is needed because the grails environment is not fired up during unit testing and we have to mock the behaviour.

Hope this helps.

--
S Vivek Krishna

http://in.linkedin.com/in/svivekkrishna


On Wed, Jun 1, 2011 at 5:51 AM, strayph <[hidden email]> wrote:
I have a problem where I am unit testing a service, but keep getting an error
when trying to save (with flush) a created domain model:
groovy.lang.MissingMethodException: No signature of method:
com.test.MyClass.save() is applicable for argument types:
(java.util.LinkedHashMap) values: [[flush:true]]

I found an article from 2009 suggesting moving the Service Unit Test to a
Service Integration Test:
http://tech.favoritemedium.com/2009/01/testing-grails-service-class.html

Is this still a valid concern?

My service does use multiple domain classes, and I am wondering about the
"right" way to unit test the service.

Thanks,

Strayph

--
View this message in context: http://grails.1312388.n4.nabble.com/Can-Service-Unit-Test-access-Domain-helper-methods-tp3564703p3564703.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Can Service Unit Test access Domain helper methods?

strayph
Thanks for that.  It does help, so I am continuing down the mock path, now that it's a bit easier.

On Jun 1, 2011, at 12:01 AM, Vivek Krishna-2 [via Grails] wrote:

HI,

Inorder for domain class helper methods to be available in unit tests, you need to mock the domain class.

This can be done with
  mockDomain(com.test.MyDomainClass, myDomainClassList) // myDomainClassList is an optional list argument which can act as a replacement for the table in DB while unit testing. 

This is needed because the grails environment is not fired up during unit testing and we have to mock the behaviour.

Hope this helps.

--
S Vivek Krishna

http://in.linkedin.com/in/svivekkrishna


On Wed, Jun 1, 2011 at 5:51 AM, strayph <<a href="x-msg://17/user/SendEmail.jtp?type=node&amp;node=3565092&amp;i=0" target="_top" rel="nofollow" link="external">[hidden email]> wrote:
I have a problem where I am unit testing a service, but keep getting an error
when trying to save (with flush) a created domain model:
groovy.lang.MissingMethodException: No signature of method:
com.test.MyClass.save() is applicable for argument types:
(java.util.LinkedHashMap) values: [[flush:true]]

I found an article from 2009 suggesting moving the Service Unit Test to a
Service Integration Test:
http://tech.favoritemedium.com/2009/01/testing-grails-service-class.html

Is this still a valid concern?

My service does use multiple domain classes, and I am wondering about the
"right" way to unit test the service.

Thanks,

Strayph

--
View this message in context: http://grails.1312388.n4.nabble.com/Can-Service-Unit-Test-access-Domain-helper-methods-tp3564703p3564703.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email






If you reply to this email, your message will be added to the discussion below:
http://grails.1312388.n4.nabble.com/Can-Service-Unit-Test-access-Domain-helper-methods-tp3564703p3565092.html
To unsubscribe from Can Service Unit Test access Domain helper methods?, click here.