views:

26

answers:

3

Hi,

Im trying to insert some test data into my database, for which a class called BootStrapTest does the work.

In my BootStrap.groovy file its called like this

environments {
            test {
                println "Test environment"
                println "Executing BootStrapTest"
                new BootStrapTest().init()
                println "Finished BootStrapTest"
            }

        }

However, when I run my integration tests, this code doesnt execute. I've read that integration tests should bootstrap, so i'm quite confused.

I saw some invasive solutions, such as modifying the TestApp.groovy script, but I would imagine that there is a road through conf to achieve this. Also read this SO question and this one as well, but didn't quite get it.

Maybe i'm misunderstanding something, I'm having a lot of trouble with grails testing. If it brings anything to the table, im using Intelli JIdea as an IDE.

Any thoughts will be appreciated.

Thanks in advance

A: 

in BootStrap.groovy you can try something like this

if (!grails.util.GrailsUtil.environment.contains('test')) {
    log.info "In test env"
    println "Test environment"
    println "Executing BootStrapTest"
    new BootStrapTest().init()
    println "Finished BootStrapTest"
} else {
    log.info "not in test env"
}
Aaron Saunders
I dont think the `BootStrap.groovy` is being executed at all.
Tom
the you are doing something else incorrectly, bootstrap must run during the integration test process
Aaron Saunders
A: 

this works for me on 1.3.4:

    def init = { servletContext ->
        println 'bootstrap'
        switch (GrailsUtil.environment) {
            case "test":
            println 'test'
            Person p=new Person(name:'made in bootstrap')
            assert p.save();
            break
            }
    }
    def destroy = {
    }
}

this integration test passes:

@Test
void testBootStrapDataGotLoaded() {
    assertNotNull Person.findByName('made in bootstrap')
}
Ray Tayek