Reputation: 3915
I'm a grails beginner. and was trying to understand the unit test ..
when i create a domain class Author
grails automatically creates a test controller AuthorControllerTests
for that domain.
so . in test controller the second line is @Mock(Author)
what does that mean.. what is the advantage i get when i mock a domain class?
Upvotes: 2
Views: 361
Reputation: 445
Just to add something, mocking is useful when you need to isolate a "unit" of code like here your controller.
By isolating, we mean write simple components to replate and simulate all dependancies. This simple components are what we call Mocks.
Grails here gives you the possibility to mock the domain class which will make your tests easier as it won't store the information in the database.
If you want to test the whole stack, from the controller to the database, it's what we call an integration test.
hope it helps
Upvotes: 1
Reputation: 171194
as it says in the extensive documentation on testing:
The Mock annotation creates mock version of any collaborators. There is an in-memory implementation of GORM that will simulate most interactions with the GORM API. For those interactions that are not automatically mocked you can use the built in support for defining mocks and stubs programmatically.
Also AuthorControllerTests are the tests for the AuthorController, not the Author domain class.
Upvotes: 1