Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix " java: package org.junit.jupiter.api does not exist "

This is my first springboot crud. Please help me to fix the errors .

package com.example1.fullstack_practice;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class FullstackPracticeApplicationTests {

    @Test
     void contextLoads() {
    }

}
like image 612
nadun channa Avatar asked Oct 20 '25 04:10

nadun channa


2 Answers

I encountered this error when changing the project's structure. I accidentally marked the 'src' directory as the Source Root, which caused the test dependencies 'spring-boot-starter-test' not to be pulled in.

Therefore, I recommend checking the project's structure. It's possible that your error is related to this.

like image 90
lain2lo Avatar answered Oct 22 '25 16:10

lain2lo


You have to add the dependency to your class path. If you are using maven add:

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.9.2</version>
    <scope>test</scope>
</dependency>

to your pom.xml

like image 22
Jens Avatar answered Oct 22 '25 18:10

Jens