org.hamcrest.Matchers.hasProperty cannot be resolved
Asked Answered
I

3

7

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

What is the alternative to use hasProperty?

Ingeringersoll answered 15/3, 2018 at 13:39 Comment(0)
K
5

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.

Kelwunn answered 15/3, 2018 at 14:4 Comment(1)
FWIW, In 2021 hamcrest-library has been replaced by the hamcrest package as follows (using Gradle notation); testImplementation org.hamcrest:hamcrest:2.2Mongol
Z
3

In case you only need it for UnitTests you can use following dependency (works with JUnit5 as well):

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-junit</artifactId>
    <version>2.0.0.0</version>
    <scope>test</scope>
</dependency>
Zillion answered 16/11, 2018 at 10:32 Comment(0)
A
0

Use this import if you are not able to use the hamcrest "equalTo" method.

import static org.hamcrest.Matchers.equalTo;

body("scope", equalTo("APP"));

Alderman answered 13/3, 2020 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.