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!
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
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>
In my case it worked by adding this line in app: build.gradle
dependencies {
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With