grails - 了解 Grails 中的单元测试

标签 grails groovy grails-2.0

我是一个 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/

相关文章:

groovy - 如何在 Groovy 中将字符串转换为整数

java - 如何将面向对象的结构映射到表单字段?

testing - 如何在jmeter的循环 Controller 中使用jsr223变量

grails - Grails应用程序中用于电子邮件提取的插件

rest - 我如何使用 Controller 来在grails 2.3.1中使用rest api?

hibernate - 如何在Grails 3中将属性传递给Enver?

facebook - grails spring-security-oauth-facebook:0.2

Grails 中数据库迁移插件的 Hibernate 问题

java - 验证 IP 地址(带掩码)

java - Grails:events.PatchedDefaultFlushEventListener - 无法将数据库状态与 session org.hibernate.StaleObjectStateException 同步