**本人进行单元测试@test的时候,突然发现执行下不了,下方显示Junit 初始化错误 initializationError!!!
注意事项:
1.测试方法必须用public修饰
2.返回值必须为void
3.方法里不能有参数
4.包下不能有类名为Test的类
5.删除导包的路径从新导包,选择JUnit4 或是JUnit5 切换调试
6.删除主类上@Ignore注解,如果加上下面的失效并不执行**
package com.test.junit;
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class FirstTest {
String str1 = "===========测试1===============";
String str2 = "===========测试2===============";
@Test
public void test1() {
System.out.println(str1);
}
@Test
public void test2() {
System.out.println(str2);
}
**7.有人说降低JUnit版本的,还有人说要导入其它jar包的.附上版本**
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<type>pom</type>
</dependency>
**8.Eclipse用户,都知道的Ctrl+S保存和 三大clean, maven Update object,object clean 等,
如果还不行,就新建一个一摸一样的工程项目->根据之前的内容一模一样地导入
(工程文件小的话建议手动导入,不要复制粘贴避免出现之前的错误)->运行就成功啦**