Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧-跳过此测试的飞道_Java_Spring_Spring Boot_Kotlin_Flyway - Fatal编程技术网

Java 弹簧-跳过此测试的飞道

Java 弹簧-跳过此测试的飞道,java,spring,spring-boot,kotlin,flyway,Java,Spring,Spring Boot,Kotlin,Flyway,带flyway的Spring Boot web应用程序 因此,我从使用H2切换到MySQL,并在必要时使用Testcontainers为后端测试提供DB 这意味着我的所有其他集成测试(即不需要数据库,但需要加载spring应用程序上下文)现在都失败了,例如UI测试,因为它们没有数据库来执行flyway迁移 [...] [main] WARN com.zaxxer.hikari.util.DriverDataSource - Registered driver with driverClassN

带flyway的Spring Boot web应用程序

因此,我从使用H2切换到MySQL,并在必要时使用Testcontainers为后端测试提供DB

这意味着我的所有其他集成测试(即不需要数据库,但需要加载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
    [...]

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

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

答案在这里