Two solutions, you can try which one works for yourself
The first: increase the version of junit to 4.x, the configuration code is as follows:
When the abnormal directory is located in \src\test\java, not \src\main\java\
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- 默认的版本为3.8.1,修改为4.x,因为3.x使用的为编程的方式,4.x为注解的形式。-->
<version>4.11</version>
<scope>test</scope>
</dependency>
The second type: remove the scope attribute
If the exception occurs in the main directory instead of the test directory, and the junit version is 4.x, the solution is to remove the scope attribute:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- 默认的版本为3.8.1,修改为4.x,因为3.x使用的为编程的方式,4.x为注解的形式。-->
<version>4.11</version>
<!-- 去掉scope作用域,使用默认的compile,编译、测试、运行都有效的作用域 -->
<!--<scope>test</scope>-->
</dependency>