Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
In short, to answer your question: You don't need to integrate TestNG with Hamcrest. Just call
org.hamcrest.MatcherAssert.assertThat(...)
directly which throwsjava.lang.AssertionError
.Background
I found your question via Google, wondering exactly the same issue. After further Googling, I didn't find any satisfying answers, so I read the source code for JUnit's integration with Hamcrest.
With JUnit, Hamcrest integration is normally used by calling:
When I read the source code, I discovered it just a small wrapper to call:
This function throws
java.lang.AssertionError
.What worked for me: 1. http://search.maven.org/
Search for 'java-hamcrest' the latest as for now is '2.0.0.0'
find dependency for Gradle (in my case)
Added compile 'org.hamcrest:java-hamcrest:2.0.0.0' to build.gradle in my project.
If you are facing problem with empty method then I would suggest to add
hamcrest
first in dependency list. or import firsthamcrest
, it will solve the problem.I was using TestNJ with rexsl(internally using Hamcrest) and it fails to find empty method. then I added rexsl first in dependency list, if you are adding library in class path you can try to add first the Hamcrest one.
hope it will help someone like me.