0

I keep getting an exception when I run my integration test:

import grails.testing.mixin.integration.Integration
import grails.transaction.Rollback
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.Specification

@Integration
@Rollback
class EmailSpec extends Specification {


    @Autowired
    EmailService service

//    def setup() {
//    }
//
//    def cleanup() {
//    }

    def 'test send email'() {
        when: 'email gets sent'
        def sendMailCalled = false
        service.metaClass.sendTestEMail = {
            sendMailCalled = true
        }
        service.sendTestEMail("test@myprovider.de")

        then:
        sendMailCalled == true
    }
}

Result:

"C:\Program Files\Java\jdk1.8.0_112\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.4\lib\idea_rt.jar=49498:C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.4\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\user\AppData\Local\Temp\classpath.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 "de.mypackeage.EmailSpec,test send email"

java.lang.IllegalStateException: No GORM implementations configured. Ensure GORM has been initialized correctly

    at org.grails.datastore.gorm.GormEnhancer.findSingleDatastore(GormEnhancer.groovy:380)
    at org.grails.datastore.gorm.GormEnhancer.findSingleTransactionManager(GormEnhancer.groovy:399)
    at de.mypackeage.EmailSpec.test send email(EmailSpec.groovy)




Process finished with exit code -1

The test already ran without problems but I don't really know why it would'nt run anymore. Any kind of help is appreciated.

The project is set up with Grails 3.3.1

Erando
  • 811
  • 3
  • 13
  • 27

2 Answers2

2

The problem was that I executed the test in IntelliJ as an JUnit test. So the grails context didn't start up and resulted in that error.

Erando
  • 811
  • 3
  • 13
  • 27
0

I run integration tests from IntelliJ frequently.

If you edit the configurations (Upper Right) -> Defaults -> JUnit Set the VM options to -Dgrails.env=test -ea

That will enable the "test" profile to be executed in intellij.

Hope it helps.