3

I try to write integration test for domain classes in my project. However each time I run the test I got some errors.

My code is below:

class ProductIntegrationTest extends GroovyTestCase {

    void testSave() {
        def product = new Product(name: "phone")
        product.save(flush: true, failOnError: true)
        assert.....
    }
}

After I run the test, the exception is:

groovy.lang.MissingMethodException: No signature of method: Product.save() is applicable for argument types: () values: []
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any()

However, if I put a @TestFor(Product) annotation for the domain class, the error has gone. I found in the document for integration test we can't put @TestFor annotation because it is only for unit test.

Anyone get some idea?

4

2 回答 2

2

迟到的答案,但我今天遇到了这个。一个可能的问题是您的test/integration目录中的另一个测试正在扩展GrailsUnitTestCase. 执行时grails test-app integration,这会给后续测试带来问题,但不会给扩展不当的测试带来问题GrailsUnitTestCase。将这些类移动到test/unit或将扩展名更改为GroovyTestCase将解决此问题。

于 2014-01-10T18:46:19.060 回答
0

我遇到了同样的错误。我发现我忘了为测试环境设置数据源。在 DataSource.groovy 中,确保您已为每个数据源设置设置了数据源以进行开发。

于 2014-04-23T20:09:16.280 回答