How to setup my-sql db for unit test in grails 3

84 Views Asked by At

I have used following code in application.yml

environments:
  test:
        dataSource:
            dbCreate: none
            url: jdbc:mysql://<<IP>>/unit_test_db
            username: ****
            password: ****

still grails use in-memory db for unit test.

1

There are 1 best solutions below

2
Jeff Scott Brown On

That may be because your test is running in the development environment. One thing that can cause that is if you are running tests directly from an IDE in such a way that grails.env is not set to test. If you run your tests using Gradle, that happens automatically. I discuss this around the 36:00 mark of the video at https://blog.jetbrains.com/idea/2017/07/webinar-recording-why-intellij-idea-is-the-premier-ide-for-grails-3/. If you are using IntelliJ that may be helpful. Another way to address the issue is to configure the IDE to delegate test running to Gradle. If you are using a different IDE, the same idea would apply but the details of how to address the issue will depend on what IDE you are using.

If you are seeing the same problem when running from Gradle, then something may be misconfigured in your project and the details of that may be tricky to identify without knowing more about the project.

I hope that helps.