By default, the required version of Hamcrest for:
There were not insiginifcant API changes between Hamcrest 1.1 and 1.3. Currently my test cases attempt to run JUnit 4.11 with Hamcrest 1.1, but I'm reasonably sure that this is a bad idea. For similar reasons, I suspect that trying to use Mockito-core 1.9.5 with Hamcrest 1.3 is also a bad idea.
What to do?
UPDATE 2015-06-12: Both Mockito 1.10.19 and 2.0.13-beta still use Hamcrest 1.1
Requires hamcrest on classpath, Mockito does not depend on hamcrest!
Introduction. 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.
Mockito provides an implementation for JUnit5 extensions in the library – mockito-junit-jupiter.
The @ExtendWith annotation is used to load a JUnit 5 extension. JUnit defines an extension API, which allows a third-party vendor like Mockito to hook into the lifecycle of running test classes and add additional functionality.
I use latest JUnit with Mockito core dependency and hamcrest 1.3 in many Maven projects at work. Till now nobody reported any problem with this. So if this works for your tests go with the newest Version for all three. Just ensure to use mockito core instead of all.
So I would recommend to go with option 2 to have all benefits of the newer versions. If you are really in doubt that anything could go wrong use option 4 which is the safest one. But of course you could go with option 2 and when in the near future anything would be wrong you could switch to option 2. Or since then a newer mockito is already out there solving this.
Note from mockito Issue 397: This problem does not appear with mockito-core.
Therefore, this issue is obsolete for those able to upgrade to Mockito 2.0.
I am not going to change the accepted answer because mszalbach deserves to keep the 15 rep, but this should be the new canonical answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With