Hamcrest is a good JUnit test jar package. This article introduces the use of hamcrest in Java.
If you have used eclipse and junit4, the use of hamcrest will make you more powerful.
1. Download hamcrest
Connect to Google and search for hamcrest.
Download list: http://code.google.com/p/hamcrest/downloads/list
Select the full hamcrest distribution version. In Linux, you can download the tgz format.
Download the ZIP file under Win. Other systems can be downloaded as needed.
2. Extract
Tar-zxvf ××× tgz
Decompress the package and place the folder in the appropriate directory. Assume the path is/home/mark/tools/hamcrest-1.2
3. hamcrest and eclipse
Suppose you have created a test project named testhamcrest and imported the junit4 package.
If not, refer to other articles on JUnit usage.
In eclipse, right-click the testhamcrest project and choose build path/Add External Archives.
Select the hamcrest-1.2 and hamcrest-core-1.2.jar under/home/mark/tools/hamcrest-library-1.2.jar.
Project:
Import static org. hamcrest. matchers .*;
Then, you can directly use the method. For more information about how to use hamcrest, see the document!
4. Trouble
Trouble: securityexception
Methond: Delete the JUnit package, and then import the JUnit package in the referenced library.