testing - How to remove object from database in test in Grails -


i have got domain:

myclass fields

string string b 

i got test:

void testremovemyclass() {      myclass x = new myclass()       x.setid(3)       x.seta("aaa")       x.setb("bbb")       x.save()      if (!myclass.exists(3)) {         fail "object not exist"     }      x.delete()      if (myclass.exists(3)) {         fail "object exists"     } } 

and second 'fail' fails. how can delete object id?

first of all: not use typed references, use:

def x = new myclass() 

very reading topic: http://blog.springsource.org/2010/07/28/gorm-gotchas-part-3/

your object still exists, should not persisted anymore. try end of test, instead of second exists():

def y = myclass.findbyid(3) assert y == null 

btw, can create domain objects eaisier via map in constructor:

def x = new myclass(id: 3, a: 'aaa', b: 'bbb') 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -