Grails @Mock annotations

I read about this annotation in the Grails documentation (Chapter 9: Testing). But I can’t understand what it is ...

The problem is that I need to mock dynamic GORM methods, is there a way to simulate them automatically, without having to write all the methods I need?

+3
source share
1 answer

This is true in grails 2.x:

When you add the @Mock (A) annotation, grails will add dynamic methods to for your unit test. You do not need to mock them.

You can do this in your test or in objects called by your test:

def s=new A().save()
A.get(1)

etc.

Grails mocks these methods using the built-in GORM memory, not jdbc.

You can also use criteria queries.

+5
source

All Articles