Hamcrest is a good JUnit test jar package. This article describes how to use hamcrest in Eclipse.
1. Download hamcrest
Search for hamcrest directly in Google.
Appendix: http://code.google.com/p/hamcrest/downloads/list
Select the Full Hamcrest distribution version. In linux, you can download the tgz format. Select Download as needed.
2. Use hamcrest in Eclipse
Decompress the package. Suppose you have created a test project named TestHamcrest and imported the JUnit4 package. In Eclipse, right-click the TestHamcrest project and choose Build Path/Add External Archive. Select the hamcrest-core-1.3.jar and hamcrest-library-1.3.jar jar files under the folder you just decompressed.
In addition, import importstatic org. hamcrest. Matchers. * In the test class .*;
Here we can use the assertThat method.
3. Problems Encountered
A SecurityException is thrown during running. Solution: remove the default Junit package from Eclipse. Follow the steps in the previous step to import the new version of JUnit. Attachment: junit-4.8.2.jar package address: http://download.csdn.net/detail/zht0627/3125442
This article is from the "Technical blog" blog, please be sure to keep this source http://liuxin0422.blog.51cto.com/7368853/1286557