【问题标题】:Spring -- skip flyway for this test春天——跳过这个测试的飞行路线
【发布时间】:2019-09-01 20:09:04
【问题描述】:

带有 flyway 的 Spring Boot Web 应用程序。

所以我从使用 H2 切换到 MySQL,并在必要时使用 Testcontainers 为我的后端测试提供数据库。

这意味着我的所有其他集成测试(不需要数据库需要加载 spring 应用程序上下文)——例如UI 测试——现在失败了,因为他们没有数据库来执行 flyway 迁移。

[...]
[main] WARN  com.zaxxer.hikari.util.DriverDataSource - Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
[main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
    [...]
    at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72)
    at org.flywaydb.core.Flyway.execute(Flyway.java:1670)
    at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)
    [...]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350
    [...]

如何为这些测试暂停飞行路线迁移?

【问题讨论】:

标签: java spring spring-boot kotlin flyway


【解决方案1】:

你应该设置spring.flyway.enabled=false。这可以通过在测试中使用特殊配置文件或在测试中使用 TestPropertySource 注释来完成。

【讨论】:

    猜你喜欢
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-22
    相关资源
    最近更新 更多