Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that spring boot org.junit.jupiter.api does not exist

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to solve the problem that spring boot org.junit.jupiter.api does not exist, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

There is no solution for org.junit.jupiter.api

The test class writing method after spring boot2.2 is inconsistent with that before.

Modified to:

/ / A code blockimport org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;@RunWith (SpringRunner.class) @ SpringBootTestclass CloudstudyApplicationTests {@ Test void contextLoads () {}} the test class error under the default test package of the new Springboot project is missing org.junit.jupiter.api

When you encounter a problem in the springboot project, record: a new ordinary Maven project An is created, and its pom.xml inheritance parent is:

Org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE

Then create a new ModuleB (Springboot project) under it. Oddly enough, after the dependency in the newly created Module is imported, the compiler reports an error (in fact, the install using Maven will also report an error)

The error is as follows

Shows that org.junit.jupiter.api does not exist, obviously a lack of corresponding dependencies.

But why is there a lack of dependence on junit? there was no such problem when building a separate springboot project before. Although the corresponding dependency can solve the problem, I still want to find out the reason. After searching on the Internet for a long time, I finally found a satisfactory answer.

Cause analysis

Spring boot 2.2 used Junit4 before and Junit5 later, resulting in a lack of packages. My new parent project A uses version 2.0.3, while the later ModuleB chooses version 2.2.4.

Solution

If you know the reason and the solution, upgrade A's parent is 2.2 or above, and test is also changed to the corresponding version. You can also directly change the test version of ModuleB to the corresponding version 2.2 of parent. Can be solved, I was simple and rude directly add junit5 dependence. As follows

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report