我是一个 Grails 初学者。并试图理解单元测试..
当我创建域类 Author
时,grails 会自动为该域创建一个测试 Controller AuthorControllerTests
。
所以。在测试 Controller 中,第二行是@Mock(Author)
这是什么意思..当我模拟域类时我得到什么好处?
最佳答案
正如 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.
此外,AuthorControllerTests 是针对 AuthorController 的测试,而不是针对 Author 域类的测试。
关于grails - 了解 Grails 中的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11272159/