information_interchange
information_interchange

Reputation: 3128

import junit jupiter api not found

I am using Junit to test some code in a Maven project in Netbeans. The dependency specified is Junit 4.12 (in the pom.xml).

However, I am getting a compiler error when I try and build:

error: package org.junit.jupiter.api does not exist

on this line: import org.junit.jupiter.api.Test;

I suspect it is a Junit4/Junit5 thing, since when I open an older version of the project in IntelliJ, it lists Junit5 as a dependency. Should I just use Junit5?

Any help in resolving the build error would be appreciated!

Upvotes: 22

Views: 81283

Answers (3)

Rahul Khatri
Rahul Khatri

Reputation: 1622

In my case it worked by adding this line in the build.gradle configuration file.

dependencies {  
    implementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
}

Upvotes: 7

Ahmed Aziz
Ahmed Aziz

Reputation: 427

I think your problem related to the <scope>test</scope>

Your test class should be in the test package.

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit-platform.version}</version>
        <scope>test</scope>
    </dependency>

Your test should be here

enter image description here

Upvotes: 5

AAryan
AAryan

Reputation: 20140

You need to Inject jupiter artefact before start writing Tests

Group ID: org.junit.jupiter
Artifact ID: junit-jupiter-api
Version: 5.0.0-M5

JUnit Jupiter is submodule of JUnit 5 so you need to use JUnit 5

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.0.0-M5</version>
    <scope>test</scope>
</dependency>

Upvotes: 19

Related Questions