Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3 + IntelliJ: Running integration tests yields "No GORM implementations configured. Ensure GORM has been initialized correctly"

I have a plain Grails 3.3.2 app. I can run tests just fine with gradle test integrationTest. But when I try to right click and run a test class or a single tests or the entire test suite in IntelliJ, I get:

No GORM implementations configured. Ensure GORM has been initialized correctly

This happens when I run them as jUnit tests.

If i try to run as Grails tests, I get:

No tests found for given includes

I have tried to clean the build and reset caches in IntelliJ, but nothing seems to help. Unfortunately I don't know what I've done to put Grails + IntelliJ in this state either. It used to work, but now it doesn't, and I'm not sure what has changed.

like image 965
August Lilleaas Avatar asked Feb 16 '18 09:02

August Lilleaas


1 Answers

I found a "fix", sort of.

I edited the @IntegrationTest annotation on my test class from:

@Integration

to

@Integration(applicationClass = Application.class)

And now it works again.

Interestingly, if I change it back to just @Integration, it still works. But if I run a clean, and rerun, it stops working. So something is definitely wonky here.

EDIT: I wrote the following test case:

CompilerConfiguration configuration = new CompilerConfiguration()
configuration.setTolerance(1)

println new File("src/integration-test/groovy/my/package/Mytest.groovy").isFile()
// true

def source = new SourceUnit(
    new File("src/integration-test/groovy/my/package/MyTest.groovy"),
    configuration,
    null,
    new ErrorCollector(configuration))

println source
// org.codehaus.groovy.control.SourceUnit@19bbb216
println source.source
// org.codehaus.groovy.control.io.FileReaderSource@6cfac0bd
println source.source.URI
// file:/path/to/my/app/src/integration-test/groovy/my/package/MyTest.groovy
println MainClassFinder.searchMainClass(source.source.URI)
// null

The AST transformation @Integration runs MainClassFinder.searchMainClass when the applicationClass property is not set. So this seems to indicate that it for some reason isn't able to automatically find the application class for my app based on the integration test. Then again, I'm not really sure which source unit it actually gets when it runs, so my test case might not be realistic.

like image 193
August Lilleaas Avatar answered Nov 15 '22 10:11

August Lilleaas