title: Integration tests with Spring Boot and MySQL
body: <p>I am familiar with Spring Data JPA and I test repositories with this kind of declaration (Spring 4):</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {PersistenceConfig.class})
  @Sql({"classpath:it-data.sql"})
  public class MyRepositoryIT {
  
      @Autowired
      private MyRepository repository;
  
      @Test
      public void someTest() {
          ...
      }
  }
  </code></pre>
  
  <p>So I am in charge of creating the MySQL schema and tables but the test class inserts test data (it-data.sql), and <code>src/test/resources/persistence.properties</code> contains the datasource config.</p>
  
  <p>Now I want to do the same thing in a Spring Boot project. I coded a simple project that works (a Controller that uses a Service to retrieve data thanks to a Repository getting data from a MySQL database).<br>
  The problem is I am not able to code a simple test that ONLY tests a repository (I don't want to load the whole app just to test a repository), I get either context errors or datasource config errors.<br>
  Starting from</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  public class MyRepositoryIT {
  
      @Autowired
      private MyRepository repository;
  
      @Test
      public void someTest() {
          ...
      }
  }
  </code></pre>
  
  <p>and duplicating <code>src/main/resources/application.properties</code> to <code>src/test/resources/application.properties</code> (just changing the schema name), I tried tons of combinations using <code>@DataJpaTest</code>, <code>@ContextConfiguration(classes = Application.class)</code>, <code>@Sql</code>, <code>@SpringBootTest</code>, <code>@AutoConfigureTestDatabase</code>, <code>@DatabaseSetup</code>, etc. But nothing works.  </p>
  
  <p>So, knowing that I have a MySQL database that already exists for my tests, what annotations should I use to insert data into it and then test autowired repositories?<br>
  Thanks.</p>