I am working with TestContainers for my project but when I am running the test in eclipse, I am having the following error with me
On top of this window, it also gives a specific error which says Cannot find test class "DBInitTest" in project "myProject".
package org.ft.cdcp;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.junit.jupiter.Testcontainers;
@Testcontainers
public class DBInitTest {
private final PostgreSQLContainer sqlContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:alpine"));
@BeforeEach
public void setUp() {
sqlContainer.start();
}
@Test
@DisplayName("Initializing database container")
public void initTest() {
assertTrue(sqlContainer.isRunning());
}
}
Do note that I have checked and rechecked the dependencies, everything is intact and there's no problem with them, something's buggy only about JUnit5.
I looked it up online but only found something which said that I should Right click on source folder --> Build Path --> Use as source path, but this fix doesn't seem to be working for me.
So I figured out what the error was.
My project structure was like this:
└─main_project/
├─ myProject/
└─ other_sub_project/
It might sound stupid but it's definitely something beginners tend to often (as I did). I have opened the main_project in my IDE and there were other sub-projects inside that projects too. The DBInitTest was inside the sub-project named myProject.
I was getting the error because of this structure only. So when I closed the project and opened the sub-project directly from the IDE, the error was gone.
Steps to resolve: