Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 495
information_interchange Avatar asked Jul 18 '17 19:07

information_interchange


3 Answers

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

like image 184
Ahmed Aziz Avatar answered Oct 21 '22 11:10

Ahmed Aziz


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>
like image 26
Abhishek Aryan Avatar answered Oct 21 '22 11:10

Abhishek Aryan


In my case it worked by adding this line in app: build.gradle

dependencies {  
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
}
like image 29
Rahul Khatri Avatar answered Oct 21 '22 11:10

Rahul Khatri