When using JUnit 4 for unit testing today, the test program has not been running, and the method Initializationerror not found error, as follows:
Online said the version is not correct, I tried, or there is this problem, later only to know that the lack of jar package, In addition to introducing Junit-4.12.jar, 2 dependent jar packages are introduced: Hamcrest-core-1.3.rc2.jar,hamcrest-library-1.3.rc2.jar, which provides free download links for everyone:
Junit-4.12.jar Download
Hamcrest-library-1.3.rc2.jar Download
Hamcrest-core-1.3.rc2.jar Download
After importing these jar packages, the problem is solved by the edge, yes, I admit I am also a novice to JUnit.
As for JUnit jar package and hamcrest jar package relationship, I quote a few words from a netizen to explain:
JUnit and Hamcrest are two different frameworks, different things. It's just that JUnit uses the Hamcrest framework.
JUnit's package decompression on JUnit opens:
Just download the JUnit jar package to unpack the files.
Junit-4.10.jar : A package containing all the contents of Junit-dep-4.10.jar and the necessary harmcres,
junit-4.10-src: Is the source code, but does not contain org.harmcres.* related source codes (in the figure Temp.hamcrest.source).
Junit-dep-4.10.jar : is a junit package, does not contain harmcres related classes, import this package also need to introduce harmcres related packages.
Download to the relevant series of packages about Hamcrest (if Java is the package to download the jar)
Hamcrest-all-1.3.orc2.ajr: Contains almost all of the hamctest classes (not verified).
Hamcrest-core-1.3.orc2.jar: Hamcrest core Package, use the package that the Hamcrest framework must introduce. (The package is included in the JUnit official package)
Hamcrest-library-1.3.orc2.jar: Contains various assertions that complement assertions in the Hamcrest core package.
Scenarios for importing packages using:Junit.jar + hamcrest-core.jar + Hamcrest-library.jar
Or:junit-dep.ajr+hancrest-all.jar
These two methods of importing, while minimizing the import of duplicate packages, still encounter conflicts when used. When you look at the categories and documents in the package, you find that some classes (for example, Assert is ()) appear in both Org.hamcrest.Mathchers and Org.hamcrest.core, which you need to be aware of when you introduce them.
Method Initializationerror not FOUND:JUNIT4 unit Test error problem