gpt4 book ai didi

java - Spring——跳过此测试的飞路

转载 作者:行者123 更新时间:2023-11-30 10:04:51 25 4
gpt4 key购买 nike

带有 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
[...]

如何暂停这些测试的飞路迁移?

最佳答案

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

关于java - Spring——跳过此测试的飞路,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55628262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com