how to avoid a domain call in unit testing with grails / spock -


i have following lines of code

username = username.stripindent() user = user."${databaseinstance}".findbyusername(username) if (user == null){    return "user not exist" } 

i'm trying unit test functionality with:

def setup() {     def mockuser = mock(user)     myclass.user = mockuser }  void "usernotfoundgetuserinfo"(){     given:     myclass.databaseinstance = 'x'     _ * mockuser._ >> null      when:     def result = myclass.getuserinfo(username)      then:     result == "user not exist" } 

but keep getting error of "no such property: x class mypackage.user"

i realize because i'm mocking "user" object , not "user" class, how around fact code making direct call domain class?

use grails built-in @mock annotation instead of spock's mock() method. go like:

@mock(user) class yourtestspecification extends specification {     def setup() {         myclass.user = new user()     } } 

@mock meant mock grails domain classes.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -