JUnit: Hamcrest usage

Source: Internet
Author: User



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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.