Intellij "java: package org.junit does not exist"

When I try to run my test, I get the following errors: I looked at google and found something on google, but that did not help.

Error:(3, 24) java: package org.junit does not exist
Error:(3, 1) java: static import only from classes and interfaces
Error:(5, 17) java: package org.junit does not exist
Error:(6, 17) java: package org.junit does not exist
Error:(12, 10) java: cannot find symbol
    symbol:   class Before
    location: class edu.kit.ipd.swt1.SimpleEditMeTest
Error:(17, 10) java: cannot find symbol
    symbol:   class Test
    location: class edu.kit.ipd.swt1.SimpleEditMeTest
[...]

My test code is:

package edu.kit.ipd.swt1;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;

public class SimpleEditMeTest {
private EditMe editMe;
@Before
public void setUp() throws Exception {
    editMe = new EditMe();
}
@Test
public void test() {
    assertNotNull(editMe.getFoo());
}
}

Screenshot of the entire project

Run configuration

Dependencies i.stack.imgur. com / OiQWU.png (cannot post more than two links)

+4
source share
2 answers

I had the same problem. To fix this, I had to open the module options for my project and manually add the jar Dependencies junit-4.12.jarand hamcrest-core-1.3.jar, which are contained in the IntelliJ installation directory.

+4
source

For those ending here using maven, a few things to check:

  • ( ) junit pom.xml?
  • Intellij maven? / Add as Maven Project , , Maven->Reimport
  • pom? <version>4.12</version>. . (, , , . .)
  • dependencyManagement? Maven , , . . :
<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

All Articles