4

From time to time I run into the issue that Grails integration tests the name of which ends in "IntegrationTests" don't work coming up with exceptions that show that GORM methods have not been added to domain classes. After renaming those tests to "*IntegrationTest" (no s at the end) they work fine.

A short example:

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

Will fail with the following exception:

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)

After renaming MyIntegrationTests to MyIntegrationTest the test passes.

Is there some kind of magic happening according to the test's name? All I found in Grails documentation is: "Tests can also use the suffix of Test instead of Tests. " Any ideas?

johanneslink
  • 4,877
  • 1
  • 20
  • 37

3 Answers3

3

I eventually found the cause for the different behaviour of "*Test" and "*Tests" myself: Different postfixes change the order in which the tests are being run. To make things worse, the exact order is platform-dependent. Thus, my tests ran locally (OSX) in a different order than on my CI machine (Linux), and thereby produced different results.

Why the exception occurrs in some order is a totally different problem, though, which I haven't figured out (yet).

johanneslink
  • 4,877
  • 1
  • 20
  • 37
0

This should work how you had it originally as long as the file is in the integration folder. Are you sure you didn't have it in the unit test folder and then move it into the integration folder on the rename? Or possibly that you're using intellij and you did a "junit" test run rather than a "grails" one?

The error you're getting seems to imply that grails didn't start up when running your test.

Ted Naleid
  • 26,511
  • 10
  • 70
  • 81
  • There was no move from unit test folder into integration test folder involved. And no, I used "grails test-app integration:" to run the tests not IntelliJ. – johanneslink Apr 26 '12 at 15:03
  • Actually when I named the integration test with suffix Spec which was default.My integration test failed?Is Spec suffix wrong in Integration test? – Rradhak May 08 '14 at 14:34
0

Your test won't be executed if it does not has the suffix Tests.

Copied From Grails documentation home page (http://grails.org/doc/latest/guide/testing.html):

The default class name suffix is Tests but as of Grails 1.2.2, the suffix of Test is also supported.

j-

murdochjohn
  • 136
  • 1
  • 2