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?

ttt
  • 3,934
  • 8
  • 46
  • 85
  • Did you put this class in `tests\integration` folder? –  Apr 30 '13 at 00:09
  • 1
    I strongly suggest to use the command grails create-integration-test to create an integration test. You would not see this issue if the test class is on appropriate directory as mentioned by @Sergio. – dmahapatro Apr 30 '13 at 00:13
  • To Sérgio, yes all the integration tests are put in the folder test/integration folder and I used the command line to generate the integration tests. – ttt Apr 30 '13 at 00:37
  • Your strongly recommendation is what I did but still have this problem. – ttt Apr 30 '13 at 00:38
  • 1
    Well then I do not see a reason why it should fail. Which version of Grails are you using? Moreover, if you are using Grails 2.x then the command line integration Test creation should yield to `ProductIntegrationTests` instead of `ProductIntegrationTest` if supplied arg is `ProductIntegration`. Can you share your domain class as well? – dmahapatro Apr 30 '13 at 01:21

2 Answers2

2

Late answer, but I ran into this today. One possible issue is that a different test within your test/integration directory is extending GrailsUnitTestCase. When executing grails test-app integration, this gives problems for subsequent tests, but not the test that is improperly extending GrailsUnitTestCase. Moving these classes to test/unit or changing the extension to GroovyTestCase will fix this issue.

Joseph
  • 1,442
  • 21
  • 44
0

I was getting the same error. I found that I had forgot to setup the data source for the test environment. In DataSource.groovy make sure you have setup a datasource for each datasource setup for development.

Gary Eberhart
  • 150
  • 1
  • 7