10 Apr 2010, 19:50
Generic-user-small

Todd Miller (3 posts)

I had trouble getting the integration tests at the end of Chapter 6 to work under Grails 1.2.2, however I was able to solve the problem. I’m posting this here to help anyone else who runs across this..

First problem was with the datasource. The DataSource.groovy for the “test” environment was still referring to hsqldb, but there was no appropriate driver for that after we switched it over to MySQL on page 88 in Chapter 5. You can provide the appropriate information to keep using the hsqldb (which makes sense to me when testing, versus persisting test data to an actual database) by modifying the test portion of DataSource.groovy to show as follows:

	test {
		dataSource {
			driverClassName = "org.hsqldb.jdbcDriver"
			username = "sa"
			password = ""
			dbCreate = "update"
			url = "jdbc:hsqldb:mem:testDb"
		}
	}

However, now you’ll get a weird error about “Could not load class type integration” that looks like this:

Error executing script TestApp: java.lang.RuntimeException: Could not load class in test type 'integration'
gant.TargetExecutionException: java.lang.RuntimeException: Could not load class in test type 'integration'
	at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:331)
	at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
	at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)

The problem causing this is apparently the “package tekdays” statement at the very top of the TaskServiceTests.groovy file. You must remove that and also add an import of all tekdays classes. A working integration test file will look like this:

import grails.test.*
import tekdays.*

class TaskServiceTests extends GrailsUnitTestCase {
    def taskService
    
    protected void setUp() {
        super.setUp()
        new TekUser(fullName:'Tammy Tester',
                    userName:'tester',
                    email:'tester@test.com',
                    website:'test.com',
                    bio:'A test person').save()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testAddDefaultTasks() {
        def e = new TekEvent(name:'Test Event',
                             city:'TestCity, USA',
                             description:'Test Description',
                             organizer:TekUser.findByUserName('tester'),
                             venue:'TestCenter',
                             startDate:new Date(),
                             endDate:new Date() + 1)
        taskService.addDefaultTasks(e)
        assertEquals e.tasks.size(), 6
    }
}

Hope this helps someone else working through these examples!

02 Aug 2010, 15:45
Generic-user-small

Wouter van Vliet (1 post)

Thanks a lot! I ran into this problem and your suggestion fixed it for me.

Regards, Wouter

20 Jan 2011, 13:56
Generic-user-small

Timothy Good (2 posts)

Todd,

I wanted to remark on the second problem you mention that you fix by getting rid of the package statement and adding the import. I am working with Grails 1.3.6. Its packaging structure has added the ‘package tekdays’ statement to the classes as well as to the directory structure it creates for the project. So when Dave says on page 104 to “move it to the integration test directory: TekDays/test/integration I did just that and it failed as you described because it could not locate the class.

To fix, I simply created this directory TekDays/test/integration/tekdays and moved the TaskServiceTests.groovy into it. At the head of my TaskServiceTests.groovy code I have:

package tekdays import grails.test.*

This seemed to do it for me.

20 Jan 2011, 16:26
Me150_pragsmall

Peter Lorent (3 posts)

Just before running this integration test I decided to import the project in SpringSource Tool Suite with the Grails extension. When using Refactor->Move, the class gets moved to the correct package test/integration/tekdays and runs without issues.

28 Aug 2011, 22:57
Generic-user-small

D.L. Molineu (2 posts)

Hello, I’m having trouble getting this test to run too. I made the changes detailed above, but am still getting the same error:

groovy.lang.MissingMethodException: No signature of method: tekdays.TekUser.save() is applicable for argument types: () values: [] Possible solutions: wait(), any(), wait(long), sleep(long), any(groovy.lang.Closure), isCase(java.lang.Object) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at tekdays.TaskServiceTests.setUp(TaskServiceTests.groovy:10) at junit.framework.TestCase.runBare(TestCase.java:132) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Any idea what I need to do to fix this? Thanks!

29 Aug 2011, 02:52
Generic-user-small

D.L. Molineu (2 posts)

Alright, dumb mistake on my part, I was running the integration test as a JUnit test (which does work for all of my unit tests). When I ran the integration test using the Run As: “Grails test-app” option it worked.

  You must be logged in to comment