Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hamcrest.Matchers.hasProperty cannot be resolved

The import org.hamcrest.Matchers.hasProperty cannot be resolved in JUnit4.12.

What is the alternative to use hasProperty?

like image 756
krish Avatar asked Mar 15 '18 13:03

krish


People also ask

What is org hamcrest matchers in?

Hamcrest is a framework for writing matcher objects allowing 'match' rules to be defined declaratively. There are a number of situations where matchers are invaluable, such as UI validation or data filtering, but it is in the area of writing flexible tests that matchers are most commonly used.

What is a hamcrest matcher?

Hamcrest is a framework that assists writing software tests in the Java programming language. It supports creating customized assertion matchers ('Hamcrest' is an anagram of 'matchers'), allowing match rules to be defined declaratively. These matchers have uses in unit testing frameworks such as JUnit and jMock.

Why are there hamcrest matchers?

Purpose of the Hamcrest matcher framework. Hamcrest is a widely used framework for unit testing in the Java world. Hamcrest target is to make your tests easier to write and read. For this, it provides additional matcher classes which can be used in test for example written with JUnit.


1 Answers

Hamcrest is not embedded in JUnit 4.12, instead you'll need to include the separate Hamcrest library on your classpath.

If you are using Maven you can do this by including the following dependency in your pom.xml:

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-library</artifactId>
    <version>1.3</version>
    <scope>test</scope>
</dependency> 

Alternatively you can download the JAR from Maven Central.

like image 158
glytching Avatar answered Sep 19 '22 23:09

glytching