How to not start Flyway when running unit tests in Spring Boot

Introduction

I'm using SpringBoot and Flyway in my current project, At the time of test execution (./gradlew test because Gradle is used in this project), There was a phenomenon that Migrate of Flyway ran. It will be one of the solutions at that time.

What kind of solution did you do

It may be obvious to those who know it, SpringBoot changes the priority of the configuration file when the test is executed. Specifically, assuming that the configuration is as follows

/project
 ├── build.gradle
 ├── gradlew
 └── src
     ├── main
     │   ├── com
     │   │    └── ...
     │   └── resources
     │       └── application.yml
     └── test
         ├── com
         │    └── ...
         └── resources
             └── application.yml

If you execute it with a jar file etc., it will read src/main/resources/application.yml, but When the test is executed, it reads src/test/resources/application.yml.

Please refer to the following article for more details on this area. Spring Boot --Change DB to read during test

Using the above characteristics, in the setting file (setting file at the time of testing) on ​​the src/test/resources/application.yml side, Added the following description to disable Flyway.

spring:
  flyway:
    enabled: false

Finally

It's nothing for those who know it, but for those who don't know it, it's a bit of a addictive point. Therefore, I wrote the article as a memorandum.

It ’s short, but that ’s it. Thank you very much.

Recommended Posts

How to not start Flyway when running unit tests in Spring Boot
How to add a classpath in Spring Boot
How to bind to property file in Spring Boot
How to write a unit test for Spring Boot 2
How to create a Spring Boot project in IntelliJ
How to use CommandLineRunner in Spring Batch of Spring Boot
How to change application.properties settings at boot time in Spring boot
How to get the log when install4j does not start
How to control transactions in Spring Boot without using @Transactional
How to use Lombok in Spring
How to unit test Spring AOP
How to set Spring Boot + PostgreSQL
Spring Boot 2.0.0 does not start built-in tomcat
How to include Spring Tool in Eclipse 4.6.3?
Story when moving from Spring Boot 1.5 to 2.1
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
How to split Spring Boot message file
How to constrain the action of the transition destination when not logged in
How to solve the problem that it is not processed normally when nesting beans in Spring Batch
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
When the server fails to start in Eclipse
How to make Spring Boot Docker Image smaller
How to use Spring Boot session attributes (@SessionAttributes)
[Rails] How to implement unit tests for models
[Spring Boot] How to get properties dynamically from a string contained in a URL
When @Transactional of Spring Boot does not work
[Grails] Error occurred running What to do when the Grails CLI does not start
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
Annotation notes when writing tests for Spring Boot
Try to automate migration with Spring Boot Flyway
How to set when "The constructor Empty () is not visible" occurs in junit
How to set environment variables in the properties file of Spring boot application
How to define multiple orm.xml in Spring4, JPA2.1
How to log in automatically when Ubuntu restarts
[Spring Boot] How to refer to the property file
Spring Boot --How to set session timeout time
How to implement authentication process by specifying user name and password in Spring Boot
Customize the display when an error such as 404 Not Found occurs in Spring Boot
How to set Dependency Injection (DI) for Spring Boot
How to make Java unit tests (JUnit & Mockito & PowerMock)
[Spring Boot] How to create a project (for beginners)
Until you start development with Spring Boot in eclipse 1
How to test file upload screen in Spring + Selenium
Introduce swagger-ui to REST API implemented in Spring Boot
How to boot by environment with Spring Boot of Maven
Until you start development with Spring Boot in eclipse 2
How to use In-Memory Job repository in Spring Batch
How to use the same Mapper class in multiple data sources with Spring Boot + MyBatis
How to solve the problem when the value is not sent when the form is disabled in rails and sent
Static resources could not be distributed from WebFlux when @EnableWebFlux was granted in Spring Boot
Let's find out how to receive in Request Body with REST API of Spring Boot
How to get the class name / method name running in Java
How to set chrony when the time shifts in CentOS7
What to do when Method not found in f: ajax
How to dynamically switch JDK when building Java in Gradle
How to not describe priority, lastmod, changefreq in gem sitemap_generator
Use Spring Test + Mockito + JUnit 4 for Spring Boot + Spring Retry unit tests
Use @ControllerAdvice, @ExceptionHandler, HandlerExceptionResolver in Spring Boot to catch exceptions
Set context-param in Spring Boot