grails, unit test mock domain with assigned id -
i using assigned id in domain
class book { integer id string name static mapping = { id generator: 'assigned' } } so add new book:
def book = new book([name: "the adventures of huckleberry finn"]) book.id = 123 book.save(flush: true) everything works perfectly, problem in unit tests
first of can mock 1 domain class, secondly, cannot use .save() on unit test, option (as far know) use mockdomain follow:
mockdomain(book, [ [id: 123, name: "the adventures of huckleberry finn"] ]) but not working, work in normal domain without "id generator: 'assigned'"
any ideas? read wouldn't face problem in integrated test, problem in unit test
you need bindable constraint id if want use (by default id not bindable) map params create domain object in unit test. domain class have
static constraints = { id bindable: true } words of advice:
if using grails > 2.x, use @mock mock domain classes instead of mockdomain. can find details unit testing in grails docs.
another level up
use build-test-data plugin mock domain objects.
Comments
Post a Comment