unit-testing - 在 Grails 应用程序中,我应该将 Groovy 类的测试用例放在哪里?

标签 unit-testing grails groovy

我的应用程序中有几个 Groovy 类,位于 src/groovy 下.相关的测试类应该去哪里,它们应该使用 GroovyTestCase或混合( TestFor )?

最佳答案

您可以为您的类(class)选择单元测试或集成测试。来自 docs你可以看到它们之间的区别:

单元测试

Unit testing are tests at the "unit" level. In other words you are testing individual methods or blocks of code without consideration for surrounding infrastructure. Unit tests are typically run without the presence of physical resources that involve I/O such databases, socket connections or files. This is to ensure they run as quick as possible since quick feedback is important.



集成测试

Integration tests differ from unit tests in that you have full access to the Grails environment within the test.



所以如果你需要访问数据库或者需要完整的环境,做一个集成测试。如果没有,请创建一个单元测试(这将使用内存数据库)。
@TestFor旨在用于单元测试,因为这将模拟基本(参见 GrailsUnitTestMixin )。如果选择集成测试,请不要使用注解。

关于unit-testing - 在 Grails 应用程序中,我应该将 Groovy 类的测试用例放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13631031/

相关文章:

unit-testing - 您如何判断单元测试是正确的?

grails - jsp 表单标签是否有 Grails 等价物?

spring - 我可以在域对象构造函数中调用grails服务吗?

mongodb - GORM 在 Grails 中使用 MongoDB 按 ID 获取/查找资源

Jenkinsfile(脚本化)将 shell $HOME 设置为 ${env.WORKSPACE}

java - 设置我使用 Clojure 对纯 Java 库进行单元测试的环境

python - 如何在不实例化新驱动程序的情况下使用 Selenium 切换 Firefox 配置文件?

java - 在 JUnit 测试(java)中如何使用 Assertj 库检查数组的数组?

android - 以一种聪明的方式根据风格排除 JNI 库

grails - 使 Grails 操作仅适用于包含