問題描述
默認情況下,Hamcrest 所需的版本用于:
By default, the required version of Hamcrest for:
- JUnit 4.11
- Hamcrest 1.3
- Hamcrest 1.1
Hamcrest 1.1 和 1.3 之間的 API 沒有變化.目前我的測試用例嘗試使用 Hamcrest 1.1 運行 JUnit 4.11,但我合理 確定這是一個壞主意.出于類似的原因,我懷疑嘗試將 Mockito-core 1.9.5 與 Hamcrest 1.3 一起使用是 也是個壞主意.
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.
怎么辦?
- 將 Hamcrest 1.1 與最新的 JUnit 和 Mockito 結合使用
- 將 Hamcrest 1.3 與最新的 JUnit 和 Mockito 結合使用
- 嘗試修補 Mockito-core 1.9.5 以使用 Hamcrest 1.3
- 我現在真的沒有時間
2015-06-12 更新: Mockito 1.10.19 和 2.0.13-beta 仍然使用 Hamcrest 1.1
UPDATE 2015-06-12: Both Mockito 1.10.19 and 2.0.13-beta still use Hamcrest 1.1
推薦答案
@durron597 于 2015 年 7 月 29 日更新:這個出色的答案在 2013 年是正確的,但后來因為 Mockito 的更新而過時.查看此答案.
我在工作中的許多 Maven 項目中使用具有 Mockito 核心依賴項和 hamcrest 1.3 的最新 JUnit.到目前為止,沒有人報告這有任何問題.因此,如果這適用于您的測試,請使用所有三個的最新版本.只需確保使用 mockito 核心而不是全部.
Update July 29, 2015 by @durron597: This excellent answer was correct in 2013, however it has since been rendered obsolete by an update to Mockito. See this answer.
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.
所以我建議使用選項 2 以獲得新版本的所有好處.如果您真的懷疑任何事情都可能出錯,請使用最安全的選項 4.但當然你可以選擇選項 2,當在不久的將來出現任何問題時,你可以切換到選項 2.或者從那時起,一個更新的 mockito 已經可以解決這個問題.
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.
來自 mockito 問題 397 的注釋:此問題不與 mockito-core 一起出現.
Note from mockito Issue 397: This problem does not appear with mockito-core.
這篇關于Mockito、JUnit、Hamcrest、版本控制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!