Junit注解不能使用,导包报错 method initializationerror not found:
单独使用junit需要导入三个包:
导入junit.jar之后还要导入hamcrest-core-1.3.jar,hamcrest-library-1.3.jar
maven:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-library -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
JUnit报错:The import org.junit.Test conflicts with a type defined in the same file
这个原因很狗血,因为省事,我创建的测试类就叫Test,但是写junit测试java类名字不能是Test,会引起冲突。把测试类名改了就OK了;
如果还是错误就是导的jar包相冲突。