【问题标题】:Grails 3 upgrade Test issuesGrails 3 升级测试问题
【发布时间】:2016-05-12 17:10:46
【问题描述】:

当我在 grails 3 中使用 Build-Test-Data 插件运行测试时,我看到以下错误。

groovy.lang.MissingMethodException: No signature of method: com...Item.save() is applicable for argument types: () values: [] Possible solutions: last(), wait(), any(), saveAll([Ljava.lang.Object;), saveAll(java.lang.Iterable), last(java.lang.String)

这通常是 .save().build() 我不是测试专家所以有人知道发生了什么吗?

更新

示例如下所示...

import grails.buildtestdata.mixin.Build

@Build(Author)
class AuthorUnitTests {

    void testAuthorStuff() {
        def author = Author.build()
        ...
    }

}

我的代码看起来像...

@TestFor(Item)
@Build([Item])
class ItemSpec extends Specification
{
  ...
  def "Blah Blah"() {
        given:
            Item i = Item.build(id: 1)
  }
}

【问题讨论】:

  • 如果是单元测试,那么 @Build(Item) 应该在类级别使用,如插件文档中所示。
  • 我有点困惑你能指出你所指的部分吗?我看到附录
  • 通过上述更新,很明显您正在使用@Build。它应该工作。您还必须手动分配id 吗?

标签: grails integration-testing grails-plugin


【解决方案1】:

在 Grails 3.1.1 中通过以下单元测试:

package com.example

import grails.test.mixin.TestFor
import spock.lang.Specification
import grails.buildtestdata.mixin.Build

@TestFor(Item)
@Build(Item)
class ItemSpec extends Specification {

    void "test something"() {
        expect:
        Item.build(name: 'Test').name == 'Test'
    }
}

build.gradle

compile 'org.grails.plugins:build-test-data:3.0.0'

确保在插件 GAV 添加到 build.gradle 后构建/编译应用程序:

gradlew build

应该这样做。

【讨论】:

  • 我正在使用 grails 3.0.11 但我可以仔细检查
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-28
  • 2020-05-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多