Error: java: package org.junit.jupiter.api does not exist

Cause of Error: java: package org.junit.jupiter.api does not exist

This java: package org.junit.jupiter.api does not exist error happens when a particular package is not added to your coding environment while you are setting it. One of the major solutions to fix this is by simply making some changes in your environment. Apart from this, there are many other ways of solving the same. 

 

The code for the following error is: 

 

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());
}
}

 

The error message comes out to be: 

 

java: package org.junit does not exist

 

Solution for Error: java: package org.junit.jupiter.api does not exist

The solutions for the same are:

For the users who are using maven, there are a few points that they must keep in mind. 

  • Adding JUnit as a dependency in your pom.xml. 
  • Intellij must accept your module as a maven module. If not then add your module as a maven module by right-clicking on it. 
  • The explicit version must have a dependency declaration in your pom file. 
  • You must have dependency management. It is a requirement by maven to resolve the correct version of your project 
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.myorg</groupId>
            <artifactId>myproject-parent</artifactId>
            <version>${myproject.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

 

 

Another solution can be adding Jar Dependencies manually in your Open Module Settings. You can find these in the installation Intellij Library directory. 

 

One more solution is by simply adding the JUnit library or by changing the JUnit dependency of your project. 

 

For those who are using Jupiter. This problem needs features for the solution:

  • Jupiter-junit-api
  • Jupiter Engine

 

One more solution in the row is to manually add the jar dependencies junit-4.12.jar and hamcrest-core-1.3.jar from the IntelliJ installation lib directory to my project’s Open Module Settings in order to fix it.

 

 

Also Read: Switch In Java

 

Share this post

3 thoughts on “Error: java: package org.junit.jupiter.api does not exist

Leave a Reply

Your email address will not be published. Required fields are marked *