Search code examples
javaeclipsejunit5testcontainers

Cannot find test class in project - "The input type of the launch configuration does not exist"


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 Error window JUnit5

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.


Solution

  • 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:

    1. Close the currently opened project i.e. main_project
    2. Click on Open Project in your IDE
    3. Navigate to the folder of the sub-project i.e. myProject and open it inside your IDE
    4. Voila, the error is gone now. ;)