The import org.junit.jupiter cannot be resolved

前端 未结 1 385
青春惊慌失措
青春惊慌失措 2021-01-28 23:30

Hey its the first time i use JUnit with Java and i\'m not sure how to set it up inside Visual studio Code. I tried to put Junit-4.13.jar inside my a lib file in the root directo

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-28 23:52

    There were 2 main issues with this configuration:

    • JUnit 4 dependency jar was used while in the source code imports from JUnit 5 API were used

    • Tests resided in the same location as sources, while the dependencies defined via Gradle/Maven for tests limit the scope to src/test/java roots.

    In a non-Gradle project the issue was fixed by adding the proper JUnit 5 dependencies to the module.

    In the Gradle project the issue was fixed by moving the test class from src/main/java to src/test/java.

    Sample Gradle project is available on GitHub.

    More details about using JUnit 5 can be found in the official documentation.

    0 讨论(0)
提交回复
热议问题