import junit jupiter api not found

Viewed 41674

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!

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

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

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