title: Configure Spring boot with H2 database and Liquibase
body: <p>I am using Spring boot2, I am trying to configure a Unit Test using H2 + Liquibase + JUNIT.</p>
  
  <p>I think that liquibase is not executing the changeLog files and apply the SQL Commands, the unit test does not recognized my tables.</p>
  
  <p>I put wrongs sql in my file to see if the changelog files are executed, but, seems that is not being executing.</p>
  
  <p>Why my application can not access table? Maybe liquibase is not executing?</p>
  
  <p>in my <em>src/test/resource</em> I have this file: <em>application.yml</em></p>
  
  <pre><code>spring:
    application:
      name: my-api
    datasource:
      driver-class-name: org.h2.Driver
      url: jdbc:h2:mem:myDB;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
      username: sa
      password: sags
    liquibase:
      enabled: true
      user: sa
      password: sags
      change-log: classpath:/db/changelog/db.changelog-master.xml
    jpa:
      hibernate:
        ddl-auto: none
        database-platform: org.hibernate.dialect.H2Dialect
      show-sql: true
      properties:
        hibernate:
          use_sql_comments: true
          format_sql: true
    h2:
      console:
        enabled: true
        path: /console
  </code></pre>
  
  <p>My Test class:</p>
  
  <pre><code>import java.util.List;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest
  public class FooRepositoryTest {
  
      @Autowired
      private FooRepository fooRepository;
  
      @Test
      public void findAllMustReturnAnything() {
          List&lt;Object&gt; result = fooRepository.tables();
      }
  }
  </code></pre>
  
  <p>The FooRepository method:</p>
  
  <pre><code>@Query(value = "SHOW TABLES", nativeQuery = true)
      List&lt;Object&gt; tables();
  </code></pre>
  
  <p>When I run my Unit Test I have the follow result:</p>
  
  <p><a href="https://i.stack.imgur.com/FLCgd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FLCgd.png" alt="enter image description here"></a></p>
  
  <p>My changelog file is in : <em>src/main/resources/db</em></p>
  
  <p>UPDATE: I found why liquibase was not executing my sql codes. It was because my SQL files had "dbms:mysql", so, how I am executing with H2 liquibase will not apply. </p>
  
  <pre><code>-- changeset 1.0:2 dbms:mysql
  command
  -- rollback command
  </code></pre>
  
  <p>Now, I need to know why my selected database in the session is not myDB.</p>