Closed Rishabhraghwendra18 closed 1 month ago
Hi, please next time consider sharing a project to reproduces the issue instead of sharing code snippets.
When using root user the password should be empty. Check Environment Variables
in https://hub.docker.com/_/mysql.
Testcontainers MySQL already handles this behavior by setting withPassword("")
instead.
@eddumelendez here's the project: https://github.com/Rishabhraghwendra18/spring-bazaar/tree/main/server
Taking a look at InventoryRepositoryTest
, I noticed this is not related to Testcontainers. @AutoConfigureTestDatabase
should be @AutoConfigureTestDatabase(replace = NONE)
, this is mentioned at the end of this section on spring boot docs. After that, the the test will hit the database.
@eddumelendez I tried your changes and still it didn't work. I have pushed my changes to the repo.
@Rishabhraghwendra18 previous to those changes tests didn't hit the database and now they are doing it. Looking at the exception, the problem is related to the application not testcontainers nor spring boot integration. TBH, this is where my support end because you know better what you are building.
Cannot add or update a child row: a foreign key constraint fails (`spring-bazaar`.`inventory`, CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`sellerId`) REFERENCES `users` (`email`))
Additional tips:
@Container
and container.start()
@ServiceConnection
and @DynamicPropertySource
. @ServiceConnection
is the modern approach if spring boot supports the testcontainers implementation.
Module
MySQL
Testcontainers version
1.19.8
Using the latest Testcontainers version?
No
Host OS
Linux
Host Arch
amd64
Docker version
What happened?
Testcontainers is getting stuck on waiting for MySQL connection. Below is my test case:
I am not getting why the MySQL test container is getting stuck on Waiting for connection (as you can see in the logs). I have followed the documentation but still not able to resolve this issue. I don't know where is the issue. Event the
@BeforeAll
annotation is not able to run.Here's my pom.xml:
application.properties file:
Relevant log output
Additional Information
No response