JUnit: hamcrest usage

Source: Internet
Author: User

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.

 

 

 

 

 

 

 

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.