Intellij “java: package org.junit does not exist”

后端 未结 5 1886
遥遥无期
遥遥无期 2021-02-07 17:33

When i try to run my test i get the following Errors: I looked up on google and found somthing on google but this didn\'t help.

Error:(3, 24) java: package org.j         


        
相关标签:
5条回答
  • 2021-02-07 18:11

    The solution to this is to add junit library as dependency to the project. This can be done by adding junit to global library and then hovering over the error(junit word) and right clicking to add junit to class path. alt+shift+ctrl+s to get project settings in the same either add junit to global library or to project section as mentioned by rob in his answer.

    0 讨论(0)
  • 2021-02-07 18:21

    I had the same problem. In order to fix it I had to Open Module Settings for my project and manually add jar Dependencies junit-4.12.jar and hamcrest-core-1.3.jar which are contained in the IntelliJ installation lib directory.

    0 讨论(0)
  • 2021-02-07 18:27

    This worked for me:

    1. Right click pom.xml
    2. Select Maven
    3. Reload project
    0 讨论(0)
  • 2021-02-07 18:32

    For anyone ending up here using maven, a couple of things to check:

    • (Sanity check) Have you added junit as a dependency in your pom.xml?
    • Have Intellij accepted your module as a maven module? Try Right clicking the module/project and select Add as Maven Project or perhaps Maven->Reimport
    • Are you using explicit version in your dependency declaration in your pom file? Like <version>4.12</version>. Try that. (You might not want to this because you want the version to be decided by a parent module. Read on.)
    • Have you remembered to add a dependencyManagement? Maven need it to resolve the correct version number if you don't want to have it explicitly in the current project. For me it refers to the parent project. Like this:
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.myorg</groupId>
                <artifactId>myproject-parent</artifactId>
                <version>${myproject.version}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    0 讨论(0)
  • 2021-02-07 18:32

    I had the same problem. Adding JARs made no difference. I solved it by adding library (not JAR) dependency for Junit 5.3

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