-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to hamcrest 2.2 #1741
Comments
Is it really possible to do this? Junit 4.13 requires a minimum JDK version of 1.5, but hamcrest 2.2 requires a minimum JDK version of 1.7. |
@linghengqian Thanks for pointing that out! You're right, we won't be upgrading in that case but it should be possible to use Hamcrest 2.2 assertions by using the dependency management capabilities of your build tool of choice. |
Note that JDK 1.6 reached EOL June, 2017 so "JUnit 4.13 requires a minimum JDK version of 1.5" shouldn't block us from considering a task ("JUnit 4 is in maintenance mode" is, of course, a consideration). Do the various build tools have a simple way to use JUnit 4.13 and Hamcrest 2.2? (I don't use maven at my work so I am unsure). |
Surely it's possible to specify newer version of Hamcrest in project dependencies. |
Unfortunately some JUnit public APIs reference Hamcrest types, so removing the dependency would be a breaking change |
Let me try to ask this in a different way. What concrete problems do people see because JUnit depends on an older version of Hamcrest? Were there API changes in Hamcrest that were not backwards compatible? |
In Android, the espresso-contrib lib updated to hamcrest 2.2 which seems to cause this problem for me. java.lang.NoClassDefFoundError: Failed resolution of: Lorg/hamcrest/Matchers;
at androidx.test.espresso.matcher.ViewMatchers.withId(ViewMatchers.java:1) This issue AdevintaSpain/Barista#357 (comment) seems related. Android devs can't move to junit5 officially and keeping junit4 with an old version of hamcrest seems problematic for the future. |
Since upgrading Hamcrest would be a breaking change, if we want to resolve this I have two questions:
|
To not break anything and have an easier transition, it would be better to have a new artefact and a new package, like what retrofit does. https://jakewharton.com/java-interoperability-policy-for-major-version-updates/ A new artefact like Please notice: I am not an expert on this stuff. |
JUnit4 has has a single artifact for over a decade and is in maintenance mode so I personally would vote against a new artifact. We will not be changing the package names for our classes. JUnit4 is the most popular Java library in the world. Major changes are costly and affect countless open source projects with shoestring budgets. |
Note that Hamcrest has a documented workaround: http://hamcrest.org/JavaHamcrest/distributables#upgrading-from-hamcrest-1x |
|
I had some free time so I did a bit of analysis. There are a few places where JUnit uses Hamcrest outside of the assert classes, and some of them would be hard to remove in a way that remained backwards compatible.
The last one looks particularly problematic. I'm not sure why Given all that, I'm not sure how doable "removing Hamcrest dependencies" would be. |
|
I'm not sure eight days constitutes "a long time ago" 🙂 @dsaff @marcphilipp any ideas why |
My guess is that at the time, we were excited about the way that hamcrest Description objects allowed for ways to be more structured than toString. Seems like something we might have been excited about at the time. (A recent-ish job transition has meant that it's more likely than it's been in at least 10 years that "People working on Android test cases experience pain because of JUnit4 issues" is something I could use paid time to look into, but I have not begun to actually do so.) |
Can we have a version of junit4 with a recent version of hamcrest?
Thanks
The text was updated successfully, but these errors were encountered: