Quantcast
Channel: Pragmatic Forums | Posts in topic 'Integration tests fail with errors'
Viewing all articles
Browse latest Browse all 6

Integration tests fail with errors posted by Todd Miller @ Sat, 10 Apr 2010 19:50:41 +0000

$
0
0

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:'<a href="mailto:tester@test.com">tester@test.com</a>',
                    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!


Viewing all articles
Browse latest Browse all 6

Trending Articles