grails - Grails 集成测试名副其实吗?

标签 grails integration-testing grails-orm

我有时会遇到这样的问题:名称以“IntegrationTests”结尾的 Grails 集成测试无法正常工作,并会出现异常,表明 GORM 方法尚未添加到域类中。将这些测试重命名为“*IntegrationTest”(末尾没有 s)后,它们工作正常。

一个简短的例子:

class MyIntegrationTests {
    @Test
    void myTest() {
        assert MyDomainClass.count() == 0
    }
}

将因以下异常而失败:

Failure:  myTest(de.myproject.MyIntegrationTests)
  groovy.lang.MissingMethodException: No signature of method: de.myproject.MyDomainClass.count() is applicable for argument types: () values: []
Possible solutions: count(), ident(), print(java.io.PrintWriter), print(java.lang.Object), getCount(), wait()
at de.myproject.MyIntegrationTests.myTest(MyIntegrationTests.groovy:9)

将 MyIntegrationTests 重命名为 MyIntegrationTest 后,测试通过。

根据测试的名称,是否发生了某种魔法?我在 Grails 文档中找到的只是:“测试也可以使用 Test 后缀来代替 Tests。”有什么想法吗?

最佳答案

我最终自己找到了“*Test”和“*Tests”不同行为的原因:不同的后缀改变了测试运行的顺序。更糟糕的是,确切的顺序取决于平台。因此,我的测试在本地 (OSX) 上运行的顺序与在 CI 机器 (Linux) 上运行的顺序不同,从而产生了不同的结果。

但是,为什么异常以某种顺序发生是一个完全不同的问题,我还没有弄清楚。

关于grails - Grails 集成测试名副其实吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10328542/

相关文章:

grails - 在一页上以不同的语言环境显示文本

grails - 抽象域类和命名查询继承?

java - elasticsearch IT 节省等待

grails - 无法重定向对象 [ManageVehicle : (unsaved)] it is not a domain or has no identifier. 请改用显式重定向

Grails Spring Security 3 字段身份验证

maven - 在Maven中运行测试时出现Geb异常

c# - 如何在api项目的Startup类中使用集成测试项目的设置?

ruby-on-rails - Cucumber 中的 RSpec 自定义匹配器到 DRY 依赖于实现的测试,这可能吗?

node.js - Grails 作为单个应用程序或不同的后端和前端应用程序

grails - Grails 中按关联计数排序