2

I have built a spring boot application. We are using flyway to manage our DB migrations. Whenever I start the maven build for my application, it basically tries to establish a connection with the database and fails. I am trying to disable this "connection to DB" step.

Now here are the solutions that I have tried:

  1. I have created a separate profile called test and I have disabled the flyway as below:
spring:
    application:
        name: ${APP_NAME:some-application}
        version:
            current: ${APP_CURRENT_VERSION:v2}
        env:
            APP_LOGGING_LEVEL: ${APP_LOGGING_LEVEL:INFO}
    flyway:
        enabled: false
    datasource:
        driver: ${RDS_DRIVER:com.mysql.jdbc.Driver}
        url: // some FB url
        username: // some DB username
        password: // some DB password
...
...
...
  1. I have assigned the profile of test to all the unit test files by using @ActiveProfiles("test") as below:
@SpringBootTest
@RunWith(SpringRunner.class)
@DirtiesContext
@AutoConfigureWebTestClient
@Slf4j
@ActiveProfiles("test")
class RefreshExternalCacheTest {
    @Autowired
    private RedisAdapter redisAdapter;
...
...
...
}

Even after disabling it through application-test.yml file and applying this profile to all the unit test files, it is still trying to set up the connection with DB. This is causing the unit tests to fail when we run the build via Jenkins.

Is there a way we can disable this setup when running the unit tests?

1 Answers1

1

Based on your spring boot version you need modified your application* yml. You can find the options/configuration here How to disable flyway in a certain spring profile?

Sounak Saha
  • 852
  • 1
  • 9
  • 21
  • I am using spring boot version verion 2.5.5. For spring versions > 2, the link that you shared says to use `spring.flyway.enabled` property, which I am already using. – Gurucharan Sharma Jan 13 '22 at 13:50